GCM Registration ID changed

后端 未结 2 2046
醉话见心
醉话见心 2020-11-30 07:19

I developed an application which used GCM technology and everything is OK.

I observed that the registration ID of the device changes after a period of time and this

相关标签:
2条回答
  • 2020-11-30 07:35

    The 'periodical' refresh never happened, and the registration refresh is not included in the new GCM library.

    The only known cause for registration ID change is the old bug of apps getting unregistered automatically if they receive a message while getting upgraded. Until this bug is fixed apps still need to call register() after upgrade, and so far the registration ID may change in this case. Calling unregister() explicitly usually changes the registration ID too.

    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.

    0 讨论(0)
  • 2020-11-30 07:39

    I read the 2 reasons over here when you GCM Registration Id might change:

    1. You’ll need to re-register every device each time you update your app.
    2. You’ll also need to re-register a device if the version of Android it’s running has been updated

    P.S: The below old answer's reference has been removed from Google's page, so might not be valid anymore

    If you see the second point under the heading Enable GCM on Architectural Overview page, it says:

    Note that Google may periodically refresh the registration ID, so you should design your Android application with the understanding that the com.google.android.c2dm.intent.REGISTRATION intent may be called multiple times. Your Android application needs to be able to respond accordingly.

    So, for handling that you should have a Broadcast Listener which could handle com.google.android.c2dm.intent.REGISTRATION intent, which Google send to the app when it has to refresh the registration ID. The broadcast receiver will have the onReceive method with an Intent. From the intent you can get the Bundle using which you can extract the new registration ID from Google. You can save that and send it to the 3rd part server to replace your previous registered ID for that user.

    Also you may see this answer on the question In GoogleCloudMessaging API, how to handle the renewal or expiration of registration ID?.

    Discussion on Should applications call gcm.register() every seven days to ensure valid registration IDs? question might also be of some use.

    Hope this helps you understand how to handle it.

    0 讨论(0)
提交回复
热议问题