我正在使用 android 文档中给出的 GCM API 和 gcm.jar。它运作良好。但是随着 GCM 刷新注册 ID,我如何以及在哪里可以收听更新的 registration id
?
GCMIntentService
类中有一个方法onRegistered(Context context, String registrationId)
这个方法可以监听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);
}
请帮忙。
最佳答案
是的,你有正确的实现。每当刷新注册 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.
关于java - 使用 GCM 读取更新的注册 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12173577/