本文整理匯總了Java中com.google.android.gcm.GCMRegistrar.getRegistrationId方法的典型用法代碼示例。如果您正苦於以下問題:Java GCMRegistrar.getRegistrationId方法的具體用法?Java GCMRegistrar.getRegistrationId怎麽用?Java GCMRegistrar.getRegistrationId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.android.gcm.GCMRegistrar
的用法示例。
在下文中一共展示了GCMRegistrar.getRegistrationId方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRegistrationId
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
public static String getRegistrationId(Context paramContext)
{
int i = Build.VERSION.SDK_INT;
if (i < 8) {
throw new UnsupportedOperationException("Device must be at least API Level 8 (instead of " + i + ")");
}
PackageManager localPackageManager = paramContext.getPackageManager();
try
{
localPackageManager.getPackageInfo("com.google.android.gsf", 0);
String str = GCMRegistrar.getRegistrationId(paramContext);
if (TextUtils.isEmpty(str))
{
FinskyLog.d("Start requesting GCM Reg Id", new Object[0]);
String[] arrayOfString = { "932144863878" };
GCMRegistrar.resetBackoff(paramContext);
GCMRegistrar.internalRegister(paramContext, arrayOfString);
str = null;
}
return str;
}
catch (PackageManager.NameNotFoundException localNameNotFoundException)
{
throw new UnsupportedOperationException("Device does not have package com.google.android.gsf");
}
}
示例2: onCreate
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
// Thread.setDefaultUncaughtExceptionHandler(new UnCaughtException(
// SplashActivity.this));
mApplication = (InternalApp) getApplication();
if (!mApplication.isTabletLayout()) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
// Automatically registers application on startup.
GCMRegistrar.register(this, CommonUtilities.SENDER_ID);
}
initiateSkillsApi();
hideActionbar();
getAllReferences();
loadControls();
loadAnimation();
}
示例3: registerGCM
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
/**
* Registers GCM and sends to server
*/
private void registerGCM() {
try {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, Config.GCM_SENDER_ID);
} else {
if (Remember.getBoolean("gcmSent", false)) {
ApiService.getClientJackson().register(
regId,
U.getDeviceId(this)
).enqueue(new Summon<Result>() {
@Override
public void onSuccess(Call<Result> call, Response<Result> response) {
Remember.putBoolean("gcmSent", true);
}
});
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: getPushNotificationSettings
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
public static void getPushNotificationSettings(Context context, RestRequest.Listener listener,
RestRequest.ErrorListener errorListener) {
if (!WordPress.hasDotComToken(context)) {
return;
}
String gcmToken = GCMRegistrar.getRegistrationId(context);
if (TextUtils.isEmpty(gcmToken)) {
return;
}
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
String deviceID = settings.getString(WPCOM_PUSH_DEVICE_SERVER_ID, null);
if (TextUtils.isEmpty(deviceID)) {
AppLog.e(T.NOTIFS, "device_ID is null in preferences. Get device settings skipped.");
return;
}
WordPress.getRestClientUtils().get("/device/" + deviceID, listener, errorListener);
}
示例5: Register
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
static void Register(Context context, Boolean force) {
taskWasForced = force;
originalContext = context;
if (force || !IsRegistered(context)) {
String regId = GCMRegistrar.getRegistrationId(context);
if (!force && regId != "") {
RegisterOnDeveloperServer(context, regId);
} else {
GCMRegistrar.setRegisteredOnServer(context, false);
try {
GCMRegistrar.register(context, APP_GCM_ID);
} catch (Exception ex) {
OnRegistrationFail(context);
}
}
}
}
示例6: setGCM
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
/**
* GCM
*/
public static void setGCM(Context context) {
//
// GCM
//
try {
GCMRegistrar.checkDevice(context);
GCMRegistrar.checkManifest(context);
final String regId = GCMRegistrar.getRegistrationId(context);
if (regId.equals("")) {
GCMRegistrar.register(context, Util.SENDER_ID);
} else {
Util.regId = regId;
Util.logDebug("Already registered - imei: " + Util.imei + " gcm: " + regId);
Util.registradoGCM = true; // marcar como registrado para no intentarlo m�s
registerOnLocalServer(context); // lo hago otra vez para asegurar
}
} catch (Exception e) {
Util.logDebug("Exception setGCM: " + e.getMessage());
}
}
示例7: getRegistrationId
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
/**
* Returns registration id associated with the specified {@link Application}.
* This method will block the thread until regId will be available.
*
* @param app
* {@link Application}
* @return registration id
*/
public static String getRegistrationId(Application app) {
// try to get regId
String regId = GCMRegistrar.getRegistrationId(app);
if (regId != null && regId.trim().length() > 0) {
return regId;
}
// wait for regId from onRegistered
try {
latch.await();
} catch (InterruptedException e) {
if (Consts.DEBUG) {
Log.i(Consts.TAG, "getRegistrationId: ", e);
}
}
regId = GCMRegistrar.getRegistrationId(app);
if (regId != null && regId.trim().length() > 0) {
return regId;
} else {
throw new IllegalStateException("getRegistrationId: Can't find regId for: " + app);
}
}
示例8: run
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
@Override
public void run()
{
Context applicationContext = getApplicationContext();
GCMRegistrar.checkDevice(applicationContext);
GCMRegistrar.checkManifest(applicationContext);
final String regId = GCMRegistrar.getRegistrationId(applicationContext);
if (regId.equals(""))
{
GCMRegistrar.register(applicationContext, GCM_PROJECT_ID);
}
else
{
Log.v("regId", regId);
}
}
示例9: getRegistrationId
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
/**
* Returns registration id associated with the specified {@link Application}.
* This method will block the thread until regId will be available.
*
* @param app
* {@link Application}
* @return registration id
*/
public static String getRegistrationId(Application app) {
// try to get regId
String regId = GCMRegistrar.getRegistrationId(app);
if (regId != null && regId.trim().length() > 0) {
return regId;
}
// wait for regId from onRegistered
try {
latch.await();
} catch (InterruptedException e) {
Log.i(Consts.TAG, "getRegistrationId: ", e);
}
regId = GCMRegistrar.getRegistrationId(app);
if (regId != null && regId.trim().length() > 0) {
return regId;
} else {
throw new IllegalStateException("getRegistrationId: Can't find regId for: " + app);
}
}
示例10: initializeGCM
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
/**
* Initializes Google Cloud Messaging
*/
private void initializeGCM() {
try {
Context context = activity.getApplicationContext();
GCMRegistrar.checkDevice(context);
GCMRegistrar.checkManifest(context);
String regId = GCMRegistrar.getRegistrationId(context);
if (regId == null || regId.trim().length() == 0 || !GCMRegistrar.isRegistered(context)
|| !GCMRegistrar.isRegisteredOnServer(context)) {
GCMRegistrar.register(context, GameBackendSettings.GCM_SENDER_ID);
}
} catch (RuntimeException e) {
Log.e(TAG, "initializeGCM", e);
}
}
開發者ID:GoogleCloudPlatform,項目名稱:solutions-griddler-sample-android-client,代碼行數:23,代碼來源:GoogleServicesFragment.java
示例11: getVertretungsplan
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
@Override
public Vertretungsplan getVertretungsplan() throws IOException,
JSONException, VersionException, UnauthorizedException {
String regId = GCMRegistrar.getRegistrationId(VertretungsplanApplication.context);
Log.d("vertretungsplan", schoolId);
String url = BASE_URL + "vertretungsplan?school=" + schoolId + "®Id=" + URLEncoder.encode(regId, "UTF-8") + "&" + VERSION;
Log.d("vertretungsplan", url);
Response response = new Request(url).getResource("UTF-8");
if(response.getResponseCode() == 400)
throw new VersionException();
else if (response.getResponseCode() == 401)
throw new UnauthorizedException();
else if (response.getResponseCode() == 200) {
Vertretungsplan v = new Gson().fromJson(response.getBody(), Vertretungsplan.class);
return v;
} else {
throw new IOException("response: " + response.getResponseCode());
}
}
示例12: gcmRegistration
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
private void gcmRegistration() {
String senderId = Preferences.getSenderId(this);
try {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String registrationId = GCMRegistrar.getRegistrationId(this);
if( registrationId != null && !"".equals(registrationId) ) {
Log.d(TAG, "Already registered. registrationId is " + registrationId);
} else {
Log.d(TAG, "No existing registrationId. Registering.");
GCMRegistrar.register(this, senderId);
}
} catch (UnsupportedOperationException e) {
Toast.makeText(this, R.string.gcm_not_supported, Toast.LENGTH_SHORT).show();
}
}
示例13: onCreate
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) { // if regId not present get one.
GCMRegistrar.register(this, "SENDER_ID");
} else { //regID already present just send a request to server to get back a notification.
HttpRequest request = new HttpRequest("POST"); //GET OR POST
request.setAction("GcmTesting");
request.setContext(getApplicationContext());
request.setGCMID(regId);
request.LoadResources(); //never forget to call this after params are set.
request.ExecuteRequest(); //this function returns a string which you echoed on the server.
//You can catch it if you want.
}
}
示例14: onCreate
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
return null;
}
}.execute();
setContentView(R.layout.activity_main);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
GCMRegistrar.register(this, "272275396485");
}
示例15: registerAtGCM
import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
protected static void registerAtGCM(Context context) {
GCMRegistrar.checkDevice(context);
GCMRegistrar.checkManifest(context);
final String regId = GCMRegistrar.getRegistrationId(context);
if (regId.equals("")) {
GCMRegistrar.register(context, SENDER_ID);
Log.v(TAG, "Already registered:sdnmbg " + regId);
} else {
Log.v(TAG, "Already registered: " + regId);
}
}