Android GCM sent successfully but not received on some devices

33,028

Solution 1

  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.

Solution 2

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

Solution 3

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.

Solution 4

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.

Share:
33,028
Jee Seok Yoon
Author by

Jee Seok Yoon

Updated on August 19, 2020

Comments

  • Jee Seok Yoon
    Jee Seok Yoon over 3 years

    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?

  • Jee Seok Yoon
    Jee Seok Yoon over 10 years
    I'm pretty sure nothing is wrong with playstore, or google account. Also, GCM just does not work(no matter if I force stop the app).
  • Andros
    Andros over 10 years
    Are you behind a firewall ? It looks like some people have issue with that.
  • Jee Seok Yoon
    Jee Seok Yoon over 10 years
    No firewall or anti-virus application... Is there any android setting that will block GCM?
  • Andros
    Andros over 10 years
    I don't think so ... like I said the correct version of PlayStore and a connected Google account. Can you post your manifest as well ?
  • Jee Seok Yoon
    Jee Seok Yoon over 10 years
    I am testing with the demo code from the official google documentation. Nothing changed(not even the package name) except that I removed "GcmBroadcastReceiver.completeWakefulIntent(intent);"
  • Andros
    Andros over 10 years
    so your application package name is "com.example.gcm" ?
  • Jee Seok Yoon
    Jee Seok Yoon over 10 years
    No, "com.google.android.gcm.demo.app".
  • Jee Seok Yoon
    Jee Seok Yoon over 10 years
    Please read the comments above... I've tested it with LTE, 3 different WIFI.
  • Jee Seok Yoon
    Jee Seok Yoon over 10 years
    Although your approach will be the first ones that everyone with GCM problems should take, but I have checked and tried all of them. Changed every setting that GCM provides, but nothing seems to work. The problem is not GCM, but GCM on "specific phones". Also, note that not releasing the wake lock solved this problem. Any other ideas?
  • Mark Whitaker
    Mark Whitaker almost 10 years
    I have the same problem, and like @JeeSeokYoon none of these steps have fixed it for me.
  • Assaf Gamliel
    Assaf Gamliel almost 10 years
    Have you checked if the Play services is connected? If not you need to call the Play services problem resolution.
  • bashan
    bashan almost 9 years
    I have similar problem, but for me the message is only "sometimes" being received. Why Google do not supply some debug tools for this process?
  • Arpit Patel
    Arpit Patel almost 8 years
    sender id = project no
  • Bam
    Bam over 4 years
    Install 'Push Notification Fixer' (install this anyway) this step worked