30

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?

Community
  • 1
  • 1
Jee Seok Yoon
  • 4,716
  • 9
  • 32
  • 47
  • Are you testing on WiFi? – Apoorv Dec 11 '13 at 08:21
  • @Apoorv No, on LTE network. Just tested it with WIFI, but no push recieved... – Jee Seok Yoon Dec 11 '13 at 08:24
  • If the message is sent successfully the regID must be wrong/invalid and google cloud messaging cannot deliver the message. – DarkLeafyGreen Dec 11 '13 at 08:34
  • @artworkadシ. However, is there cases that result.getErrorCodeName() return null even when regId is wrong/invalid? – Jee Seok Yoon Dec 11 '13 at 08:38
  • @JeeSeokYoon http://developer.android.com/google/gcm/http.html no. – DarkLeafyGreen Dec 11 '13 at 08:41
  • Is there a relation between the OS version and devices where GCM does not work? For example only on Android 2 or Android 3? – paolo2988 Dec 13 '13 at 20:51
  • @v1sc3rr4k It seems like a 4.1 jellybean problem. – Jee Seok Yoon Dec 13 '13 at 21:24
  • It would help if you post your client code - the manifest, the broadcast receiver and the service. – Eran Dec 14 '13 at 02:01
  • @Eran Well... I am testing with the [demo code](https://code.google.com/p/gcm/source/browse/#git%2Fgcm-client) from the official google documentation. Nothing changed(not even the package name) except that I removed "GcmBroadcastReceiver.completeWakefulIntent(intent);". – Jee Seok Yoon Dec 16 '13 at 13:17
  • I have the same problem. The demo code seems to work fine with Android 4.4, but other devices (testet with Android 2.3.4, 4.0.3, 4.1) do not receive the push notification – sockeqwe Dec 19 '13 at 11:19
  • Are you sure that this problem is for 4.1 or anything else can be , have you tried all other devices? – keshav Dec 20 '13 at 09:40
  • I'm seeing exactly the same problem. 4 devices on my desk, all switched on, on the same WiFi network, running the same app. All registration IDs are correct and I've tried many different options in my GCM request from the server. Two of the 4 devices have never received a GCM message, the other 2 always receive every one. The main difference I can see is that the devices that receive are on 4.3 and 4.4.2, the two that don't receive are on 4.1.2. – Mark Whitaker May 16 '14 at 12:47
  • @JeeSeokYoon Did you ever find a solution to this problem? I'm seeing exactly the same thing. – Mark Whitaker May 16 '14 at 14:32
  • @MarkWhitaker Sorry, not yet. However, I've been using the temporary solution(that I've added in the question), and they seem to work fine... – Jee Seok Yoon May 16 '14 at 16:38
  • By the way, did you call completeWakefulIntent() at the end of onHandleIntent() or where exactly? – Leo DroidCoder Aug 24 '16 at 20:34

4 Answers4

18
  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.
Edward Brey
  • 40,302
  • 20
  • 199
  • 253
Assaf Gamliel
  • 11,935
  • 5
  • 41
  • 56
  • 1
    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? – Jee Seok Yoon Dec 19 '13 at 09:45
  • I have the same problem, and like @JeeSeokYoon none of these steps have fixed it for me. – Mark Whitaker May 16 '14 at 12:46
  • Have you checked if the Play services is connected? If not you need to call the Play services problem resolution. – Assaf Gamliel May 16 '14 at 13:06
  • 8
    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? – bashan Jun 28 '15 at 15:53
  • sender id = project no – Arpit Patel May 02 '16 at 16:52
2

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.

Andros
  • 4,069
  • 1
  • 22
  • 30
  • I'm [pretty sure](http://developer.android.com/google/gcm/client.html#sample-play) nothing is wrong with playstore, or google account. Also, GCM just does not work(no matter if I force stop the app). – Jee Seok Yoon Dec 16 '13 at 12:56
  • Are you behind a firewall ? It looks like some people have issue with that. – Andros Dec 16 '13 at 14:41
  • No firewall or anti-virus application... Is there any android setting that will block GCM? – Jee Seok Yoon Dec 17 '13 at 12:24
  • 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 ? – Andros Dec 17 '13 at 13:44
  • 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);" – Jee Seok Yoon Dec 17 '13 at 14:06
  • so your application package name is "com.example.gcm" ? – Andros Dec 17 '13 at 14:38
  • [No](https://code.google.com/p/gcm/source/browse/gcm-client/AndroidManifest.xml), "com.google.android.gcm.demo.app". – Jee Seok Yoon Dec 17 '13 at 15:34
2

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

Dehan Wjiesekara
  • 3,152
  • 3
  • 32
  • 46
2

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.

BricoleurDev
  • 827
  • 9
  • 14