I followed the steps outlined in the Google GcmClient application and generated a registerId which is stored in my SharedPrefs. Thus, the identifier register is regenerated only when appVersion changes.
This reg-id is sent to my server (based on Rails), and notifications are sent to the Android device through the GCM gem ( https://github.com/spacialdb/gcm ).
Problem: sometimes the server receives an “unregistered” response, although the same register identifier worked just a minute before the failure.
When this happened, I tried to "clear the data", and the newly created reg-id is different from the last ... Is it possible that the registration identifier has expired, without an application, has been updated (of course, I do not call without registration)?
I read posts about similar issues and Google, but still can not determine what is common to all of these failures. The problem also occurred when downloading the application from GoogleStore (during production) and without updating the application.
The main method that registers with GCM:
public static void register(Context context, IGcmRegisterationListener listener) { try { MyLog.v("GcmClient: Registering for GCM..."); Context appContext = context.getApplicationContext(); // Check device for Play Services APK. If check succeeds, proceed with // GCM registration. if (checkPlayServices(appContext)) { MyLog.v("GcmClient: Looking for GCM regId locally"); String currentRegId = getRegistrationIdFromPrefs(appContext); if (currentRegId == null) { MyLog.v("GcmClient: GCM regId not found."); registerInBackground(appContext, listener); } else { MyLog.v("GcmClient: GCM regId found: " + currentRegId); listener.onGcmRegistered(context, currentRegId); } } else { MyLog.i("GcmClient: No valid Google Play Services APK found."); listener.onGcmRegistrationFailed(); } } catch (Exception ex) { MyLog.i("GcmClient: GCM registration failed: " + Log.getStackTraceString(ex)); listener.onGcmRegistrationFailed(); } }
source share