Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android GCM sent successfully but not received on some devices

On the server side, I am using GCM server 1.0.2 library provided by Google. On the client side, I set up GCM as provided on the official documentation.

My problem is that everything works fine on most devices, but on few devices, push is not recieved.

if (case1)     message = new Message.Builder()         .timeToLive(0)         .collapseKey("0")         .delayWhileIdle(false)         .addData("msg", msg).build(); else if (case2)     message = new Message.Builder()         .collapseKey("2")         .addData("msg", msg).build(); else     message = new Message.Builder().addData("msg", msg).build();  Result result = sender.sendNoRetry(message, regId); System.out.println("Message ID:"+result.getMessageId()); System.out.println("Failed:" + result.getErrorCodeName()); 

From what I can see from tests with the above code, there are no error. The message id is present, but error code name is null(which is a sign of successful push).

I've tried almost every setting. Tested with TTL, collapse key, delay while idle set on and off.

What are some cases that can cause to block(?) GCM push? And how can I resolve this?

EDIT

I have no idea why but the temporary solution below solved my problem.

In GcmIntentService#onHandleIntent just remove

GcmBroadcastReceiver.completeWakefulIntent(intent); 

This line releases the wakeful service. I am curious though because on other devices, push messages are sent continuously even when this line was not removed.

This is not a solution because this document states that I should call completeWakeFulIntent after each work. Also, my method will drain the battery significantly.

Any suggestion?

like image 313
Jee Seok Yoon Avatar asked Dec 11 '13 08:12

Jee Seok Yoon


People also ask

What is difference between GCM and FCM in Android?

FCM is a cloud platform that provides messages and push notifications for operating systems- ios and Android, and websites as well. Google Cloud Messaging is a messaging service that enables the message transfer from server to clients apps.

How does GCM push notification work?

The first step in GCM is that a third-party server (such as an email server) sends a request to Google's GCM server. This server then sends the message to your device, through that open connection. The Android system looks at the message to determine which app it's for, and starts that app.

Is GCM and FCM same?

Firebase Cloud Messaging (FCM), formerly known as Google Cloud Messaging (GCM), is a cross-platform cloud solution for messages and notifications for Android, iOS, and web applications, which as of June 2022 can be used at no cost.

Is GCM reliable?

We evaluate GCM in real world experiments, and at a reasonable scale involving thousands of real users. Our findings reveal that the GCM message delivery is unpredictable, namely having a reliable connection to Google's GCM servers on the client device does not guarantee a timely message arrival.


1 Answers

  1. Make sure you've set your SENDER ID you've received from Google correctly.
  2. Make sure your device was registered with Google's GCM service correctly.
  3. Make sure you are sending the push to the correct reg id you've received from Google. and that you didn't receive an error from Google GCM service.
  4. Have you set the delay_while_idle = 1? This means the message won't reach the device if it's idle (off, offline, locked screen, etc...). Change it to delay_while_idle = 0 if you want your wakelock permission to make any difference. Please read more here.
  5. Some times it takes time for the push to arrive (but never too much time, then there is a problem). Check what's the "time to live" of the push you've sent.
like image 143
Assaf Gamliel Avatar answered Sep 20 '22 01:09

Assaf Gamliel