當前位置: 首頁>>代碼示例>>Java>>正文


Java GCMRegistrar類代碼示例

本文整理匯總了Java中com.google.android.gcm.GCMRegistrar的典型用法代碼示例。如果您正苦於以下問題:Java GCMRegistrar類的具體用法?Java GCMRegistrar怎麽用?Java GCMRegistrar使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GCMRegistrar類屬於com.google.android.gcm包,在下文中一共展示了GCMRegistrar類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onDestroy

import com.google.android.gcm.GCMRegistrar; //導入依賴的package包/類
@Override
protected void onDestroy() {
    super.onDestroy();

    if (mGCMRegisterTask != null) {
        LOGD(TAG, "Cancelling GCM registration task.");
        mGCMRegisterTask.cancel(true);
    }

    try {
        GCMRegistrar.onDestroy(this);
    } catch (Exception e) {
        LOGW(TAG, "C2DM unregistration error", e);
    }

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    sp.unregisterOnSharedPreferenceChangeListener(this);
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:19,代碼來源:BaseActivity.java

示例2: onSuccessHttpOperation

import com.google.android.gcm.GCMRegistrar; //導入依賴的package包/類
@Override
public void onSuccessHttpOperation(String responseData) {
	Log.d(SmartConstants.APP_NAME, "PushMessageNotifier->onSuccessHttpOperation->current event:" + this.currentEvent + "response data:" + responseData);
	hideLoadingIndicator();
	switch (currentEvent) {
	case CURRENT_EVENT_PUSH_REGISTER:
		GCMRegistrar.setRegisteredOnServer(context, true);
		notifierPushMessageListener.onPushRegistrationCompleteSuccess(prepareResponseFromCurrentEventSuccess(currentNotifierEvent, new JSONObject()));
		// String message = SmartConstants.GCM_SERVER_REGISTERED_MESSAGE;
		// displayMessage(context, message);
		break;

	case CURRENT_EVENT_PUSH_UNREGISTER:
		// TODO call the device unregister function here
		GCMRegistrar.setRegisteredOnServer(context, false);
		notifierPushMessageListener.onPushRegistrationCompleteSuccess(prepareResponseFromCurrentEventSuccess(currentNotifierEvent, new JSONObject()));
		// String message = SmartConstants.GCM_SERVER_UNREGISTERED_MESSAGE;
		// displayMessage(context, message);
		break;
	}
}
 
開發者ID:appez,項目名稱:appez-android,代碼行數:22,代碼來源:PushNotificationUtility.java

示例3: onErrorHttpOperation

import com.google.android.gcm.GCMRegistrar; //導入依賴的package包/類
@Override
public void onErrorHttpOperation(int exceptionData, String exceptionMessage) {
	Log.e(SmartConstants.APP_NAME, "PushNotificationUtility->onErrorHttpOperation->exceptionData:" + exceptionData + ",exceptionMessage:" + exceptionMessage);
	hideLoadingIndicator();
	switch (currentEvent) {
	case CURRENT_EVENT_PUSH_REGISTER:
		GCMRegistrar.setRegisteredOnServer(context, false);
		notifierPushMessageListener.onPushRegistrationCompleteError(prepareResponseFromCurrentEventError(currentNotifierEvent, exceptionMessage));
		break;

	case CURRENT_EVENT_PUSH_UNREGISTER:
		GCMRegistrar.setRegisteredOnServer(context, false);
		notifierPushMessageListener.onPushRegistrationCompleteError(prepareResponseFromCurrentEventError(currentNotifierEvent, exceptionMessage));
		break;
	}
}
 
開發者ID:appez,項目名稱:appez-android,代碼行數:17,代碼來源:PushNotificationUtility.java

示例4: 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");
  }
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:27,代碼來源:GcmRegistrationIdHelper.java

示例5: 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();
}
 
開發者ID:himanshuagarwal77225,項目名稱:BookMySkills,代碼行數:26,代碼來源:SplashActivity.java

示例6: 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();
    }
}
 
開發者ID:alashow,項目名稱:datmusic-android,代碼行數:28,代碼來源:MainActivity.java

示例7: removeWpComUserRelatedData

import com.google.android.gcm.GCMRegistrar; //導入依賴的package包/類
public static void removeWpComUserRelatedData(Context context) {
    // cancel all Volley requests - do this before unregistering push since that uses
    // a Volley request
    VolleyUtils.cancelAllRequests(requestQueue);

    NotificationsUtils.unregisterDevicePushNotifications(context);
    try {
        GCMRegistrar.checkDevice(context);
        GCMRegistrar.unregister(context);
    } catch (Exception e) {
        AppLog.v(T.NOTIFS, "Could not unregister for GCM: " + e.getMessage());
    }

    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
    editor.remove(WordPress.WPCOM_USERNAME_PREFERENCE);
    editor.remove(WordPress.ACCESS_TOKEN_PREFERENCE);
    editor.commit();

    // reset all reader-related prefs & data
    AppPrefs.reset();
    ReaderDatabase.reset();

    // Reset Simperium buckets (removes local data)
    SimperiumUtils.resetBucketsAndDeauthorize();
}
 
開發者ID:ldsddn,項目名稱:wordpress_app_android,代碼行數:26,代碼來源:WordPress.java

示例8: 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);
}
 
開發者ID:ldsddn,項目名稱:wordpress_app_android,代碼行數:21,代碼來源:NotificationsUtils.java

示例9: onDestroy

import com.google.android.gcm.GCMRegistrar; //導入依賴的package包/類
@Override
protected void onDestroy() {
	// TODO Auto-generated method stub
	
	unregisterReceiver(SmsIntentReceiver);
	if (mRegisterTask != null) {
		mRegisterTask.cancel(true);
	}
	try {
		unregisterReceiver(mHandleMessageReceiver);
		GCMRegistrar.onDestroy(this);
	} catch (Exception e) {
		Log.e("UnRegister Receiver Error", "> " + e.getMessage());
	}
	super.onDestroy();
}
 
開發者ID:halimbimantara,項目名稱:Arduscam,代碼行數:17,代碼來源:MainActivity.java

示例10: onDestroy

import com.google.android.gcm.GCMRegistrar; //導入依賴的package包/類
@Override
protected void onDestroy() {
    super.onDestroy();

    if (mGCMRegisterTask != null) {
        LogUtils.LOGD(TAG, "Cancelling GCM registration task.");
        mGCMRegisterTask.cancel(true);
    }

    try {
        GCMRegistrar.onDestroy(this);
    } catch (Exception e) {
        LogUtils.LOGW(TAG, "C2DM unregistration error", e);
    }

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    sp.unregisterOnSharedPreferenceChangeListener(this);
}
 
開發者ID:The-WebOps-Club,項目名稱:saarang-iosched,代碼行數:19,代碼來源:BaseActivity.java

示例11: 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);
			}
		}
	}
}
 
開發者ID:deepankarb,項目名稱:android-Notifier,代碼行數:19,代碼來源:Registration.java

示例12: RegisterOnDeveloperServer

import com.google.android.gcm.GCMRegistrar; //導入依賴的package包/類
static void RegisterOnDeveloperServer(Context context, String registrationId) {
	for (int i = 0; i < 3; i++) {
		boolean success = post(context, registrationId);
		if (success) {
			GCMRegistrar.setRegisteredOnServer(context, true);
			OnRegistrationSuccess(context);
			return;
		} else {
			try {
				Thread.sleep(2000);
			} catch (Exception ex) {
				break;
			}
			
		}
	}
	OnRegistrationFail(context);
}
 
開發者ID:deepankarb,項目名稱:android-Notifier,代碼行數:19,代碼來源:Registration.java

示例13: register

import com.google.android.gcm.GCMRegistrar; //導入依賴的package包/類
private void register(String regId) {
	SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
	try {
		Studentportal.getSportalClient().postGCMRegistrationId(regId);
		GCMRegistrar.setRegisteredOnServer(this, true);
		Preferences.setNotificationsEnabled(this, preferences, true);
		// only get notifications from the time of registering, none of the time before
		Preferences.setNotificationsLastCheckDate(this, preferences, new Date());
		GCMStatusBroadcastCommunicator.sendBroadcast(this, 
				new Intent().putExtra(GCMStatusBroadcastCommunicator.EXTRA_GCM_UP, true));
	} catch (Exception e) {
		Log.e(TAG, "gcm registering on campus failed", e);
		/* If registering at the campus server fails, unregister from GCM to avoid an illegal app
		 * state where the app thinks it is registered but the campus server doesn't know about its
		 * existence. 
		 * A new registration try will be executed on the next app start. */
		GCMUtils.unregister(this);
		Preferences.setNotificationsEnabled(this, preferences, false);
		GCMStatusBroadcastCommunicator.sendBroadcast(this, 
				new Intent().putExtra(GCMStatusBroadcastCommunicator.EXTRA_GCM_UP, false));
	}
}
 
開發者ID:protyposis,項目名稱:Studentenportal,代碼行數:23,代碼來源:GCMCampusService.java

示例14: clearRegistrationId

import com.google.android.gcm.GCMRegistrar; //導入依賴的package包/類
/**
 * Clears the registered GCM ID and makes the GCM library think that the app isn't 
 * registered at GCM.
 * After this method has been called, the ID is still stored in the GCM system and
 * also on the campus server for the previous user. Sooner or later the GCM will
 * invalidate the ID (either because it's getting too old or it notices that no client
 * responds to messages with this ID [just my wild guess]), similar to the process
 * described here: http://developer.android.com/google/gcm/adv.html#unreg
 * At some later time the campus server might want to send a message to the device
 * with this ID, get the answer from GCM that the ID is invalid and delete it from
 * it's database.
 * The GCM library does exactly the same after the app has been updated to a new
 * version, so this procedure should be save and the server infrastructure should
 * be able to handle it.
 */
public static void clearRegistrationId(Context context) {
	try {
		/* The method is private and therefore needs to be accessed by reflection.
		 * Maybe Google doesn't want app to call it directly, but the alternative would
		 * be to set up a much more complicated workflow that first unregisters the app,
		 * and then checks in the onUnregistered handler if some flag is set that tells
		 * the app to register again. The advantage would though be, that the ID gets
		 * invalidated instantly in the GCM system. */
		Method m = GCMRegistrar.class.getDeclaredMethod("clearRegistrationId", Context.class);
		m.setAccessible(true);
		m.invoke(null, context);
	} catch (Exception e) {
		Log.e(TAG, "reflection call to clear regId failed", e);
		Analytics.onError(Analytics.ERROR_GCM_CLEAR_REGID, e);
	}
}
 
開發者ID:protyposis,項目名稱:Studentenportal,代碼行數:32,代碼來源:GCMUtils.java

示例15: doInBackground

import com.google.android.gcm.GCMRegistrar; //導入依賴的package包/類
@Override
protected Void doInBackground(Context... params)
{
	GCMRegistrar.unregister(params[0]);
	try
	{
	    Class.forName( "com.amazon.device.messaging.ADM" );
	}
	catch (ClassNotFoundException e)
	{
	    return null;
	}
	final ADM adm = new ADM(KlyphApplication.getInstance());
	adm.startUnregister();
	return null;
}
 
開發者ID:jonathangerbaud,項目名稱:Klyph,代碼行數:17,代碼來源:KlyphADM.java


注:本文中的com.google.android.gcm.GCMRegistrar類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。