3

In which time frequency the GCM server refresh the registration ID. If it is changed how to get regId changed event in my mobile?

My Application registers on GCM on first time launch and store the regId Id in Sahred Preference file. Then it will get regId from shared Pref and send to our server when user done some event manually.

My Problem is,How to find the reg Id refreshed in GCM Server. Then only i can create a event to update on server to update reg Id.

Ramprasad
  • 7,981
  • 20
  • 74
  • 135

3 Answers3

1

When the regid changes on the GCM server, then it is your server which is responsible for updating the regid in its database.

It is only possible because the old regid still works (at least once anyway) and tells your server in its response to the message sent with the old regid by means of the canonical_id, which will contain the new regid that you should use in future. Have a look at the dev docs and advanced topics for a full explanation

NickT
  • 23,844
  • 11
  • 78
  • 121
0

See http://developer.android.com/google/gcm/gs.html.

You need to add the BroadcastReceiver to your application as per the directions on this page. You then create a GCMIntentService class, which extends GCMBaseIntentService. Have that service upload the registration ID to your app server (or store it in shared preferences for later).

Karakuri
  • 38,365
  • 12
  • 84
  • 104
  • so i cannot get event in mobile? – Ramprasad Feb 19 '13 at 05:00
  • You shouldn't rely on your Activity to receive the registrationId because your Activity may no longer be running. Also, the GCM server may issue a new registrationId at any time in the future because it decides to expire the old one, without you requesting a new one. That's why they instruct you to create a `BroadcastReceiver`. – Karakuri Feb 19 '13 at 05:07
  • But onRegistered,onUnregistered,onMessage,onError,onRecoverableError methods only avaialble. Where i get onRegId changed event? – Ramprasad Feb 19 '13 at 05:18
  • From the documentation: "onRegistered(Context context, String regId): Called after a registration intent is received, passes the registration ID assigned by GCM to that device/application pair as parameter. Typically, you should send the regid to your server so it can use it to send messages to this device." I've updated the response as well. – Karakuri Feb 19 '13 at 05:27
  • This method is fine when i request a GCM reg Id from mobile.But how to get event when i did not send request but RegId changed in GCM server. – Ramprasad Feb 19 '13 at 06:36
  • That is why you use a `BroadcastReceiver`. BroadcastReceivers can receive broadcasts from the system, which is what happens when the device receives a new regId from GCM server. – Karakuri Feb 19 '13 at 15:34
  • Should the mobile App check for change in registration ID in regular intervals to update reg ID on server ? – Tushar Sep 23 '13 at 12:42
  • When you get an ID, whether it was requested or not, you will get a broadcast that your BroadcastReceiver should receive. Make your update there and you are done. It doesn't need to be anymore complicated than that. – Karakuri Sep 23 '13 at 20:11
0

As per http://developer.android.com/google/gcm/client.html#sample-register, unlike previous versions of GCM and C2DM, Google itself does not refresh the registration. Once you have the registration id from the initial registration you are good to go, except for one case: you do still need to re-register when the user upgrades to a new version (this case is also handled in the example in the link above).

When an application is updated, it should invalidate its existing registration ID, as it is not guaranteed to work with the new version. Because there is no lifecycle method called when the application is updated, the best way to achieve this validation is by storing the current application version when a registration ID is stored.

Shivanand Darur
  • 3,158
  • 1
  • 26
  • 32