1

I am a beginner in android, trying to use GCM services, I am able to register devices and receive messages from server through GCM.

The problem comes when the server stops sending the messages for a while.

Just for testing purposes i am running this loop on the server, to send messages to the device, every 5 secs.

for (;;) {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Content content = createContent();//the data to send to the client
        PostGcm.post(apikey, content);
    }

The client receives it without delay, No Problem!

But when I increase the sleep time to minutes, the message delivery becomes erratic. However on the server, I get the success message from the GCM, which makes me think there is a problem on GCM side

I have looked up on similar question on StackOverflow but didn't get an answer/solution for it. Temporary solution is to restart the phone/network connection.

This is my message

{
    {    
         "time_to_live": 60,
         "delay_while_idle": false,
         "data": {
             "title": "Title",
             "message": "Message"
    },
    "registration_ids":["REGISTRATION ID"]
}
Community
  • 1
  • 1
j4rey
  • 2,582
  • 20
  • 34
  • have u change package name and have u change any api key in android – Naveen Tamrakar Nov 12 '14 at 10:23
  • @NaveenTamrakar he can send push notification at the beginning, thus its key should work. OP, you should set `delay_while_idle` to `true`, see [this](http://stackoverflow.com/a/19537656/188331) – Raptor Nov 12 '14 at 10:26
  • Its the same name and apikey that i created the project with, did not change it. The problem is not that i am not receiving messages, the problem is that when there is a long interval between messages, the message don't get delivered. – j4rey Nov 12 '14 at 10:26
  • @Raptor i set `delay_while_true` to `true` and for 5 mins interval its delivering the message. The thing is, it waits for the user to unlock the phone before delivering the message. Weirdly when `delay_while_true` is set to `false` the message doesn't get delivered for 5 mins interval. – j4rey Nov 12 '14 at 11:56
  • @Raptor when `delay_while_true` is set to `true` and sending message with 5 mins interval, the message gets delivered for a first few but then it stops delivering after a while. Then need to switch on airplane mode then back to start receiving the queue message. – j4rey Nov 12 '14 at 13:01
  • I came upon this similar question in Google Groups [Delay in getting GCM notification](https://groups.google.com/forum/#!msg/android-gcm/Y33c9ib54jY/vmJRFv0SmKYJ) which talks about the same problem. It has some workaround to this problem which involves pinging at regular intervals to keep the connection alive. – j4rey Nov 12 '14 at 13:05

0 Answers0