1

我已经实现了 GCM 的全部功能,并且一切正常。当我启动应用程序时,我得到了regId,一切看起来都很好。但是我的 GCMIntent 服务似乎时不时地停止接收传入的消息。我想知道 GCM 服务是否有问题,有没有办法检查通知是否已发送到设备。下面是我要注册的客户端代码,然后是我的 GCMIntent 服务。

GCMRegistrar.checkDevice(this);
        GCMRegistrar.checkManifest(this);
        if(GCMRegistrar.isRegistered(this))
        {
            final String regId = GCMRegistrar.getRegistrationId(this);//app_preferences.getString(Constants.KEY_DEVICE_TOKEN, "");;
            if(!regId.equals(""))
            {
                mRegIds= regId;
                //sendIdToServer(regId);
                Log.i("DEVICE TOKEN", regId);
                is_gcm_registered = true;
            } 
        }

        else
        {
            GCMRegistrar.register(this, Constants.SENDER_ID);
            is_gcm_registered = false;
        }

GCM 意向服务:

@Override
protected void onMessage(Context context, Intent intent) {
    Log.e("GOT INCOMING MESSAGE","HI");
    // My implementation
}

问题是有时它会立即生效,有时可能需要 1 到 2 分钟才能收到通知。这是正常的吗?

编辑:我正在阅读 GCM Throttling http://developer.android.com/google/gcm/adv.html#throttling 并且它说如果将消息批量发送到同一设备,则应用程序会用完令牌。那么 GCM 不是实现即时消息应用程序的最佳方式吗?

4

1 回答 1

0

是的,延迟是正常的——尤其是当手机进入睡眠状态几分钟时。您会注意到,如果您积极使用手机,消息往往会立即到达。

不要太担心 - 消息最终会到达。

于 2012-12-24T09:13:46.460 回答