Android GCM在一段时间后停止传递消息
我是android的初学者,尝试使用GCM服务,我能够注册设备并通过GCM从服务器接收消息 当服务器停止发送消息一段时间后,问题就会出现 为了测试,我在服务器上运行这个循环,每5秒向设备发送一次消息Android GCM在一段时间后停止传递消息,android,google-cloud-messaging,Android,Google Cloud Messaging,我是android的初学者,尝试使用GCM服务,我能够注册设备并通过GCM从服务器接收消息 当服务器停止发送消息一段时间后,问题就会出现 为了测试,我在服务器上运行这个循环,每5秒向设备发送一次消息 for (;;) { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); }
for (;;) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Content content = createContent();//the data to send to the client
PostGcm.post(apikey, content);
}
客户及时收到,没问题
但当我将睡眠时间增加到几分钟时,消息传递就会变得不稳定。然而,在服务器上,我从GCM获得了成功消息,这使我认为GCM方面存在问题
我查阅了StackOverflow的类似问题,但没有得到答案/解决方案。临时解决方案是重新启动电话/网络连接
{
{
"time_to_live": 60,
"delay_while_idle": false,
"data": {
"title": "Title",
"message": "Message"
},
"registration_ids":["REGISTRATION ID"]
}
让你更改包名,并让你更改中的任何api密钥android@NaveenTamrakar他可以在开始时发送推送通知,因此它的键应该可以工作。OP,您应该将
delay\u while\u idle
设置为true
,查看它与我创建项目时使用的名称和apikey相同,但没有更改它。问题不在于我没有收到消息,问题在于当消息之间的间隔很长时,消息不会被传递。@Raptor我将delay\u设置为true
,而将\u true
设置为true
,每隔5分钟发送消息。问题是,它会等待用户在发送信息之前解锁手机。奇怪的是,当delay\u while\u true
设置为false
时,消息在5分钟的间隔内没有发送。@Raptor当delay\u while\u true
设置为true
并以5分钟的间隔发送消息时,消息先被发送了几分钟,但一段时间后停止发送。然后需要打开飞行模式,然后返回以开始接收队列消息。