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?
I read the 2 reasons over here when you GCM Registration Id might change:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With