Question

I have an app that receives GCM notifications and updates local data in background through a Service (classic pattern).

Documentation says that, if an app update occurs, the registration id may become useless and a check for a new registration id is needed. The sample provided by Google (DemoActivity) shows that, soon, in the OnCreate (or OnResume) of the main activity the check should be done.

But, what if the user updates app through Play Store and doesn't open the app soon after? In this case, is there a risk that, after the update, the registration id becomes invalid and notifications stop to be received (and my background Service stops to update local data)?

Or maybe this case is managed by the Google GCM server with the "canonical IDs" mechanism?

Thank you,
Max

Was it helpful?

Solution

A blog post by Pushbullet detailed a solution to this problem: create a BroadcastReceiver which listens for PACKAGE_REPLACED:

<receiver android:name=".UpdateReceiver">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_REPLACED" />
        <data android:path="<YOUR_PACKAGE_NAME_HERE>"
              android:scheme="package" />
    </intent-filter>
</receiver>

Which will be called whenever your app is updated. When this is called, you should forget your registration id and re-register with GCM.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top