Android GCM: How to detect registered canonical id

2019-06-04 21:20发布

问题:

I have an app published at the play store. When I want to send a notification, some users (for example, me) receive duplicate messages. I know that I have to handle it when I send the messages to recover the canonical ids and update the old registered id. But, Can I do something to fix this situation without sending any notification?

回答1:

You should figure out a way to notify your server when GCM sends your app a new registration id.

Currently when you get a registration id from GCM, you send it to your server, which probably adds it to your DB without checking if that id should replace an old id.

In order to detect that case, and update the old id instead pf inserting a new one, you should assign your own unique id to each app instance, and send it to the server along with the reg id. You should persist that id in external storage, so that it survive even if your app is uninstalled and then installed again.