相关疑难解决方法(0)

在具有两个GCM BroadcastReceivers的应用程序中偶尔出现GCM错误:INVALID_SENDER

我继承了一个已经实现了GCM服务的应用程序并且运行良好.

我说的很好,因为有一半时间,当应用程序启动时,我得到错误INVALID_SENDER而另一半我得不到它!

我得到错误的时间和我没有得到的时间之间没有区别(或者我可能错过了差异).

我不时从GCM收到消息(当我INVALID_SENDER登录后没有得到)

这是onCreate()我主要活动中的注册码

private void registerGCM() throws Exception {
    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this);
    registerReceiver(mHandleMessageReceiver, new IntentFilter(
            CommonUtilities.DISPLAY_MESSAGE_ACTION));
    final String regId = GCMRegistrar.getRegistrationId(this);
    if (regId.equals("")) {

        // Automatically registers application on startup.
        GCMRegistrar.register(this, CommonUtilities.SENDER_ID);
    } else {


        // Device is already registered on GCM, check server.
        if (GCMRegistrar.isRegisteredOnServer(this)) {


            ServerUtilities.register(mContext, regId);
        } else {
            // Try to register again, but not in the UI thread.
            // It's also necessary to cancel the thread onDestroy(),
            // …
Run Code Online (Sandbox Code Playgroud)

android push-notification google-cloud-messaging

2
推荐指数
1
解决办法
5391
查看次数