In the official docs and this question, Google recommend re-registering GCM because the registration ID could change.
One hypothesized way it can happen is that during update, the all is uninstall and then installed. If a GCM notification is received during that gap, NotRegistered
could be returned and the GCM registration ID could be invalidated.
If Google Play updates my app automatically, what's the most robust way to deal with that kind of scenario and re-register? In an app like WhatsApp, the user may never explicitly launch any activity unless a GCM notification is received. So the user is basically "lost" until he accidentally stumbles upon an activity.
In https://stackoverflow.com/a/14955308/111021 it is mentioned that the "Canonical ID" will be included so that the 3rd party server can update the registration ID. But in the doc it is not explicitly stated that this kind of scenario is covered (i.e. GCM may mistake the app as "uninstalled" during the update gap, in which case it seems to me a canonical ID will not be generated and I'll go straight to NotRegistered
).
How does a "high availability" app like WhatsApp or other messager apps deal with this?
What about below solution:
Create a BroadcastReceiver for intent ACTION_PACKAGE_REPLACED. You will receive this intent when a new version of the package gets installed. Once you get this intent you can re-register to GCM for new registration Id.
Broadcast Action: A new version of an application package has been installed, replacing an existing version that was previously installed. The data contains the name of the package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With