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?
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?
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.
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.
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.
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.
SENDER ID
you've received from Google correctly.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.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With