Android Learner
Android Learner

Reputation: 2579

Read updated registration id using GCM

I am using GCM API and gcm.jar given in android documentation. Its working good. But as GCM refreshes registration id how and where can I listen updated registration id?

There is a method onRegistered(Context context, String registrationId) in class GCMIntentService is this the method which can listen registration id (either that id was refreshed by GCM)? Or is there any other way to listen updated registration id? and another confusion Is there any test case where I can test with updated registration id?

My current implementation of onRegistered() is

@Override
    protected void onRegistered(Context context, String registrationId) {
        Log.i(TAG, "Device registered: regId = " + registrationId);

        dataStore = new DataPrefStore(context);
        //Store registration Id
        dataStore.setRegistrationId(registrationId);
        //Notify GCM registration
        displayMessage(context, Constants.GCM_REGISTER_MESSAGE);

    }

Please help.

Upvotes: 1

Views: 914

Answers (1)

Dusean Singh
Dusean Singh

Reputation: 1484

Yes, You have right implementation. Whenever the registration id is refreshed it will call your GCMINtentService class onRegistered() method.

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.

Upvotes: 1

Related Questions