DeadlyDroid
DeadlyDroid

Reputation: 92

Android Push Notification Regsitration Id Validation

I had set up the GCM notificaion in android . with in one year i am getting so many device id for same device. Is there any way to validate the Regsitraion id

I know on sending the push notification to old id it will gives the new id . But i need to clear my Db is there any way to do it?

Upvotes: 0

Views: 477

Answers (1)

Eran
Eran

Reputation: 393811

First of all, if you handle registration to GCM in the client side properly, you should be getting many registration IDs for the same device.

You should store the registration ID in the app's shared preferences, and register again to GCM only when a new version of your app is installed on the device (that's what Google recommend to do).

To handle the case of your app being uninstalled and installed again, you can generate a unique instance identifier for each device. Send that identifier to your server along with the registration ID. Store that identifier in the device's external storage, so it won't get deleted when your app is uninstalled. Try to restore it from external storage (if it's available) when your app is installed. Now, if you get a new registration ID, but still have the original instance identifier, when you send them to your server, your server will see it already has an old registration ID for that instance identifier, and will replace the old registration ID with the new one (instead of creating a new record).

Second of all, if you fail to avoid the creation of duplicate registration IDs for the same device in your DB, your only option to detect them is by sending a GCM message to the registration ID and handling the returned canonical registration ID. You could, however, send a message with dry_run=true, which simulates the sending of a message without actually sending it. I just tested it with an old registration ID. The message wasn't delivered, but I got the response with the canonical registration ID.

dry_run If included, allows developers to test their request without actually sending a message. Optional. The default value is false.

Upvotes: 2

Related Questions