java - 使用 GCM 读取更新的注册 ID

标签 java android google-cloud-messaging

我正在使用 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/

相关文章:

java - Spring 应用程序中通过 ReactJS REST 生成的文件列表为空

android--如何使用measure getPressure

android - 我可以将普通 View 用作小部件吗?

android - 在 cordova 插件中获取上下文

java - 游戏框架中的订单相关实体

javascript - 如何使用javascript ajax调用下载txt文件

java - 为什么添加 <merge> 会改变 android 布局?

android - 当 EditText 在 Android 中获得焦点时,TextView 停止水平滚动

android - 已收到 GCM 消息但未显示 - 广播接收器结果=已取消 - 服务强制停止

c# - Xamarin Google Cloud Messaging GcmClient.CheckDevice(this) 导致运行时错误