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:
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:
What is the best practice for handling canonical ids?
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.
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