使用GCM读取更新的注册ID

时间:2012-08-29 08:19:16

标签: java android google-cloud-messaging

我正在使用Android文档中给出的GCM API和gcm.jar。它的工作性很好。但是,当 GCM刷新注册ID 时,我可以在何处以及在哪里收听更新的registration id

onRegistered(Context context, String registrationId)中有一个方法GCMIntentService这个方法可以监听registration id(这个ID是否被GCM刷新)?或者有没有其他方式来监听更新的注册ID?另一个混乱是否有任何测试用例我可以使用更新的注册ID进行测试?

我目前的onRegistered()实施是

@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);

    }

请帮忙。

1 个答案:

答案 0 :(得分:1)

是的,你有正确的实施。每当刷新注册ID时,它将调用GCMINtentService类onRegistered()方法。

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.
相关问题