@@ -0,0 +1,1406 @@
+package com.kevinquan.google.gcm;%0A%0Aimport android.content.BroadcastReceiver;%0Aimport android.content.Context;%0Aimport android.content.Intent;%0Aimport android.util.Log;%0A%0A/**%0A * Implements pattern described in: http://stackoverflow.com/a/23863974/1339200%0A *%0A * Force re-registration of GCM ID if package is replaced (re-installed).%0A * Note that this will remove the existing GCM ID which may be undesirable%0A * depending on how many pushes the application gets%0A *%0A * Remember to add an entry into AndroidManifest with intent filter:%0A%09%09%09%3Cintent-filter%3E%0A                %3Caction android:name=%22android.intent.action.MY_PACKAGE_REPLACED%22 /%3E%0A            %3C/intent-filter%3E%0A * @author Kevin Quan (kevin.quan@gmail.com)%0A *%0A */%0Apublic abstract class PackageReplacedReceiver extends BroadcastReceiver %7B%0A%0A%09private static final String TAG = PackageReplacedReceiver.class.getSimpleName();%0A%0A%09protected abstract Intent getRegisterGcmIdService(Context context);%0A%0A%09@Override%0A%09public void onReceive(Context context, Intent intent) %7B%0A%09%09if (context == null %7C%7C intent == null) %7B%0A%09%09%09return;%0A%09%09%7D%0A%09%09if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) %7B%0A%09%09%09Log.d(TAG, %22Own package is being replaced, Re-register GCM ID%22);%0A%09%09%09removeExistingGcmId(context);%0A%09%09%09context.startService(getRegisterGcmIdService(context));%0A%09%09%7D%0A%09%7D%0A%0A%09protected void removeExistingGcmId(Context context) %7B%0A%09%09new Gcm().removeRegistrationId(context);%0A%09%7D%0A%7D%0A

handle GCM re-registration pattern