Android C2dm : Duplicate Message To The Same Device And App
Solution 1:
Not sure if this is the best approach, but there's a relevant thread over at the android-c2dm group, where the poster offers one technique:
I am sending registration id in the message, so I can check it against the stored registration id on the device.
If it's not the same, discard it and notify the service that registration Id is no longer in use
Downside is sending registration Id takes up some space in already limited message size. But works perfectly in my case since my original message is no more than a few chars long.
Solution 2:
This should only happen for the first push notification after re-installing your application.
Google C2DM service is working in passive mode when it comes to detecting uninstalled applications.
First push notification after uninstalling your application (without unregistering from C2DM!!!) will NOT return any error in response. However, the second push notification will return an "invalid registration" or "not registered" error codes where you can realize the application was uninstalled.
The reason is that C2DM servers return the response code immediately and only then tries to push the client. When client respond that an application was uninstalled, it is deleted from C2DM servers. Next push attempt will return an error code immediately.
Solution 3:
Another solution could be to provide your server with a unique identifier for the device. In that case you can just update the registrationID for that UUID when the device tries to register after re-installation.
Solution 4:
Yup, I've run into the same issue and in my opinion it's a big oversight in the Android C2DM implementation. iOS handles this much better in that an app can only ever receive notifications for one and only one device token (equivalent of the c2dm registration id)
The workaround I use is to send the last 10 characters of the registration id as part of the c2dm payload and then in my onMessage method I do the following check:
if (!regId.endsWith(bundle.getString("regsuffix"))) returnnull;
Solution 5:
Both @Zamel and @johan answers are good and need to be combined. If you combine both solutions than you will minimize your server's database.
So the best solution will be to:
Send device id when sending the push token to the server
Update push token when is sent for existing device id
- Invalidate push token in the server's database, if push notification returns an "invalid registration" or "not registered" error codes to the server
When push token is recognized as "invalid registration" or "not registered" you can invalidate it(mark it as null), delete the row in the database or implement expiration functionality. It depends on your needs
Post a Comment for "Android C2dm : Duplicate Message To The Same Device And App"