Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping app GCM registration ID valid robustly during automatic updates

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?

like image 627
kizzx2 Avatar asked Jul 13 '13 04:07

kizzx2


1 Answers

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.

like image 76
Vineet Shukla Avatar answered Oct 19 '22 07:10

Vineet Shukla