GCM Registration ID changed

坚强是说给别人听的谎言 提交于 2019-12-17 07:28:55

问题


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 has caused a problem in my app because my app is dependent on the Reg ID.

So how I can get a fixed Reg ID for clients?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/17893117/gcm-registration-id-changed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!