我已经实现了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不是实现Instant Messaging应用程序的最佳方式吗?
答案 0 :(得分:0)
是的,延迟是正常的 - 特别是当手机进入睡眠状态几分钟时。您会注意到,如果您正在使用手机,则信息会立即到达。
不要太担心 - 消息最终会到达。