Android GCM and multiple tokens

后端 未结 5 1854
失恋的感觉
失恋的感觉 2020-12-03 21:36

I register in GCM with GoogleCloudMessaging.getInstance(context); and save received token on device. Then send it to server and it\'s associated with user account. If I uni

5条回答
  •  一生所求
    2020-12-03 21:51

    I experienced registration ID changes when uninstalling the application, attempting to send messages to the app while it's uninstalled (until I get a NotRegistered error) and then installing again.

    Costin Manolache from Google suggests to handle registration ID changes this way :

    The suggestion/workaround is to generate your own random identifier, saved as a shared preference for example. On each app upgrade you can upload the identifier and the potentially new registration ID. This may also help tracking and debugging the upgrade and registration changes on server side.

    Of course, this only works when the app remains installed (since shared preferences are deleted with the app). However, if the device has external storage, you can store your identifier there, and when the app is installed again, load the stored identifier from the external storage. That way you will know the new Registration ID and the old Registration ID belong to the same device.

    In addition, you should handle canonical registration ID responses from Google in your server, as mentioned in the other answer.

提交回复
热议问题