8

I have an android app that relies on GCM push notifications, and sometimes, a user's device will stop receiving push notifications. The behavior is quite intermittent: on some devices, it will never fail and just keep working for weeks or months, while on other devices, it will work for a few days, and then just randomly stop receiving pushes.

Every time the device has stopped working, I've verified that the device has a valid regId from GCM, and that my server is sending pushes to that regId. However, the logs show that the device is not receiving anything. Here is what the logs on a normal push receive looks like:

05-15 10:39:21.091: V/GCMBroadcastReceiver(13766): onReceive: com.google.android.c2dm.intent.RECEIVE
05-15 10:39:21.091: V/GCMBroadcastReceiver(13766): GCM IntentService class: com.medigram.v2.GCMIntentService
05-15 10:39:21.091: V/GCMBaseIntentService(13766): Acquiring wakelock
05-15 10:39:21.111: V/GCMBaseIntentService(13766): Intent service name: GCMIntentService-468134393228-13
05-15 10:39:21.131: V/GCMBaseIntentService(13766): Releasing wakelock
05-15 10:39:21.171: V/GCMBroadcastReceiver(13766): onReceive: com.google.android.c2dm.intent.RECEIVE
05-15 10:39:21.171: V/GCMBroadcastReceiver(13766): GCM IntentService class: com.medigram.v2.GCMIntentService
05-15 10:39:21.171: V/GCMBaseIntentService(13766): Acquiring wakelock
05-15 10:39:21.241: V/GCMBaseIntentService(13766): Intent service name: GCMIntentService-468134393228-14
05-15 10:39:21.271: V/GCMBaseIntentService(13766): Releasing wakelock

None of this shows up on the devices that have stopped receiving pushes, and as a result, neither is the onMessage() method of my GCMIntentService called.

The strange thing is, when I switch the device connection from 3G/4G to wifi or vice versa, it starts working again, and the device gets all the backlogged pushes at once. What exactly happens when the connection type changes?

In case it helps, here are some things I've tried on devices where push is working to manually reproduce the problem, but to no avail:

-I first thought it could be a context issue, but that was quickly ruled out when simply switching networks resolved the issue. I tried investigating further anyway by using the 'Dont keep activities' developer option and then backgrounding the app, but this had no effect on push.

-I've tried force stopping the app to see if it would cause push to stop working, but the issue doesn't seem to have anything to do with the app being force stopped, as it keeps working.

-I've tried putting the phone on airplane mode and coming back, but push kept working.

I would greatly appreciate it if somebody could point me in the right direction, as I've pretty much exhausted all of the resources on stackoverflow and the google. I'm still just as clueless about this issue as when I started.

Kara
  • 6,115
  • 16
  • 50
  • 57
rotinegg
  • 226
  • 2
  • 8
  • 2
    possible duplicate of [this](http://stackoverflow.com/questions/13835676/google-cloud-messaging-messages-sometimes-not-received-until-network-state-cha) – Eran May 15 '13 at 20:41
  • Can you provide a little insight into your project's setup? Is it a library project? Does your app invoke GCM handling from a library project? Under which circumstances does your app register on GCM, and does it ever unregister? – Paul Lammertsma Sep 09 '13 at 10:01
  • Have you found a solution for this ? Even i am facing same problem. – keen Mar 14 '14 at 06:27
  • 2
    FYI: You can dial `*#*#426#*#*` and check if the device is connected to Google Play Services, when it stops to receive push notifications. Also have a look at [this thread on google forum](https://productforums.google.com/forum/#!msg/nexus/fslYqYrULto/lU2D3Qe1mugJ) for more information on used ports, heartbeat intervals, etc... – Baris Akar Aug 05 '15 at 12:02
  • Can u upload the code that u have actually sent... Possibility could be many.... – Rahul Raina Aug 17 '15 at 07:28
  • I think, the GCMBroacCastReceiver is receiving the push, but it is not starting the service that shows you the notification... or may be the gcmBroadCastReceiver is not started.. – Rahul Raina Aug 17 '15 at 07:30
  • 1
    I know this post is really old, but just confirming that I too am encountering exactly the issue you describe with GCM. It occurs on some devices with long running applications after a week or two. It seems to be system-wide: other apps also stop receiving push notifications. An on/off toggle of WiFi results in push notifications being delivered again. So maybe a solution is to periodically toggle WiFi programatically? – Michael Pedersen Dec 15 '15 at 07:07
  • Still happening in september 2016 with fcm 9.4.0 – Tim Sep 12 '16 at 09:39

1 Answers1

0

Typically Android send a heartbeat every 28 minutes on mobile connection and every 15 minutes on Wifi, so you can fix this by broadcasting these two intents in shorter interval from your app.

com.google.android.intent.action.MCS_HEARTBEAT

com.google.android.intent.action.GTALK_HEARTBEAT

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

you can read in detail here

Nishant Pardamwar
  • 1,450
  • 12
  • 16