How to avoid delay in Android GCM messages / change heartbeat

Ferran Maylinch picture Ferran Maylinch · Oct 24, 2013 · Viewed 32.9k times · Source

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.

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.

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.

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?

Thanks a lot


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

Answer

Renan Grativol picture Renan Grativol · May 28, 2014

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"));

Hope it help you!