Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registration ID duplication for GCM

We have an app that uses GCM. When user firstly opens the app,app checks the shared preferences to look whether user is registered previously.if not the registration id is taken from GCM and stored to shared preferences. There is also a 3rd party server where user id and registration ids are stored. I read and implemented the following cases for canonical id issues:

  1. During sending notification,if a new registration id (canonical id) is received, the old registration id is updated with the canonical id in the 3rd party server.
  2. When user uninstalls the app, and when the 3rd party server sends a notification to uninstalled app registration id,not registered message is received and registration id is deleted from 3rd party database.

As a developer we have many registration ids stored in the database. Because we uninstall and install app frequently. Normally user will not do this. Then we considered using device id as a unique id for the device and check whether user registered previously. Is it ok to use android device id for this? What should i consider to prevent multiple registration ids for a device? These multiple registration ids cause multiple pushes to an Android device. The multiple registration ids mainly caused by:

  1. The app was uninstalled and reinstalled recently. How can i detect user uninstalled and installed and already have a registration id?
  2. The cache was cleared and/or the data was cleared for the app recently. How can i detect user cleared the app data and already hava an registration id?

What is the best practice for handling canonical ids?

like image 959
Murat Avatar asked May 25 '14 12:05

Murat


1 Answers

To handle the situation of a user uninstalling and re-installing the app (or clearing the app data), I'd store the user id (or whatever identifier you use to identify an application instance on a specific device) in the external storage of the device. This storage won't get wiped when user uninstalls the app or clears the app data (it can still be deleted manually by the user, but there's nothing you can do about that).

Then, when you launch the app, if user data is not available in shared preferences, you attempt to restore it from the external storage. Only if it's not available in the external storage, you assume this is a new installation of the app on a new device and register to GCM (in addition, you are also advised to re-register to GCM whenever a new version of your app is installed).

And if all this handling at the client side fails, you still get a chance to remove duplicate registration IDs from the server, whenever you get a canonical registration ID in the response from Google.

like image 145
Eran Avatar answered Oct 30 '22 01:10

Eran