我按照Google GcmClient应用程序中给出的步骤生成了存储在我的SharedPrefs中的registrationId . 这样,只有在更改appVersion时才会重新生成register-id .

此reg-id被发送到我的服务器(基于Rails),并通过GCM gem(https://github.com/spacialdb/gcm)将通知发送到Android设备 .

The problem: Sometimes the server receives "not registered" response although the same register-id has worked just a minutes before the failure.

当发生这种情况时,我试着"clear data"并且新生成的reg-id与最后一个不同... Is is possible that a registration-id is expired without the application is updated (of course I'm not calling unregister)?

我阅读了类似问题的帖子并谷歌但仍无法确定所有这些失败的常见现象 . 当我从GoogleStore( 生产环境 中)下载应用程序而不更新应用程序时,也出现了此问题 .

注册到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();
    }
}