如何避免 Android GCM 消息延迟/更改心跳 [英] How to avoid delay in Android GCM messages / change heartbeat

查看:25
本文介绍了如何避免 Android GCM 消息延迟/更改心跳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了许多关于影响某些人的 GCM 问题的帖子.似乎在某些设备/路由器/运营商中,通知会出现延迟.我的路由器遇到过这个问题:消息在 WIFI 上有很长的延迟,但当我禁用 WIFI 并连接到移动网络时立即出现.

I've been reading many posts regarding a GCM issue that affects some people. It seems that in some devices/routers/carriers the notifications suffer delays. I've experienced this issue with my router: messages came with a lot of delay on WIFI but came instantly when I disabled WIFI and connected to the mobile net.

似乎有一种解决方法可以从 Android 应用程序中完成.诸如增加使 GCM 连接保持活动状态的心跳之类的东西.

It seems there is a workaround that can be done from the Android app. Something like increasing the heartbeat that keeps GCM connection alive, or so.

谁能告诉我们应该怎么做才能避免延误?我们如何从 Android 应用程序保持与 GCM 的连接?代码示例(以及在何处以及如何使用它)会非常有帮助.

Can anyone tell us what should we do to avoid the delay? How can we keep the connection with GCM from an Android app? A code example (and where and how to use it) would be really helpful.

这篇文章解释了这个问题.它说我们可以每两分钟从 GCM 服务器(这是免费的)通过 ping 保持连接有效".我们该怎么做?

This post explains the problem. It says that "we could keep the connection alive with a ping every two minutes from the GCM server (which is free)". How can we do that?

非常感谢

以下应用似乎可以解决问题.令人惊讶的是,第一个不需要任何许可,第二个互联网连接,第三个仅适用于已root的手机:

The following apps seem to do the trick. Surprisingly, the first one doesn't need any permission, the second one internet connection and the third one is only for rooted phones:

https://play.google.com/store/apps/details?id=at.pansy.droid.gcmWifiFix

https://play.google.com/store/apps/details?id=com.elotro.pushheartbeat

https://play.google.com/store/apps/details?id=com.andqlimax.pushfixer

推荐答案

我会把它作为评论放在第一个答案中,但我没有足够的声誉.

I would put this as a comment in the first answer but I don't have enough reputation.

我遇到了类似的问题,我在调用我的网络服务之前执行下面的代码解决了它.

I had a similar issue and I solved it executing the code below before calling my webservice.

context.sendBroadcast(new Intent("com.google.android.intent.action.GTALK_HEARTBEAT"));
context.sendBroadcast(new Intent("com.google.android.intent.action.MCS_HEARTBEAT"));

希望对你有帮助!

这篇关于如何避免 Android GCM 消息延迟/更改心跳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆