Jee Seok Yoon
Jee Seok Yoon

Reputation: 4816

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?

Upvotes: 30

Views: 33210

Answers (4)

Assaf Gamliel
Assaf Gamliel

Reputation: 12015

  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.

Upvotes: 18

BricoleurDev
BricoleurDev

Reputation: 827

Checklist

  • Make sure Google Play Store is updated to latest version
  • Make sure there are no systemwide settings for notifications which are blocking
  • Go into app in Application Manager and uncheck/recheck 'Notifications'
  • If on Wifi, switch Wifi connection to a different AP (if possible)
  • Reboot the device
  • Install 'Push Notification Fixer' (install this anyway)

First-run notification setup can be annoyingly arbitrary and require the device be 'kicked' in one or more of these ways.

Upvotes: 2

Dehan Wjiesekara
Dehan Wjiesekara

Reputation: 3182

if you are using wifi, may be the internet firewall block the gcm. try to use internet with your mobile sim card.

Upvotes: 2

Andros
Andros

Reputation: 4069

Do you have the correct version of the Playstore to receive the notification ? Are you logged with a functional Google Account on those devices ?

I also had a problem when I "Force stop" an app, you can't receive notification on any app after a "force stop" (start with android 3.1) so be careful with that too.

Upvotes: 2

Related Questions