Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
842 views
in Technique[技术] by (71.8m points)

google cloud messaging - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...