notRegistered"是什么错误由code&QUOT的意思;使用GCM发送推送消息时? [英] what does mean by error code "notRegistered" when sending push messages using GCM?
问题描述
我想通过以下code以将通知发送到通过Java服务器注册的设备:
I am trying to send push notification to the registered device through Java server by following code:
import java.io.IOException;
import java.util.ArrayList;
import com.google.android.gcm.server.Constants;
import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.MulticastResult;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;
public class Test {
private void sendNotification()
{
try{
Sender sender = new Sender("AIzaSyD9GblH8c9qCBqDhLPKMca3dH8JsY4cgjg");
ArrayList<String> devicesList = new ArrayList<String>();
devicesList.add("APA91bEtN2c3FYSFPpW-KuNtkWT6B9NJUviKN0L0DCjviJ2BtMyhZLqsFSFKfsySI1s88I0u68xETjvpqhvepffRSgwoTmpRXAv0Fbr0gH8CLhHO5CJC-M8");
String data = "hi.......";
Message message = new Message.Builder()
.collapseKey("1")
.timeToLive(3)
.delayWhileIdle(true)
.addData("message",
data)
.build();
MulticastResult result = sender.send(message, devicesList, 1);
sender.send(message, devicesList, 1);
System.out.println(result.toString());
if (result.getResults() != null) {
int canonicalRegId = result.getCanonicalIds();
if (canonicalRegId != 0) {
System.out.println("hi...");
}
} else {
int error = result.getFailure();
System.out.println(error);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String ar[])
{
new Test().sendNotification();
}
}
和我收到以下错误:
MulticastResult(multicast_id=7574342191790679138,total=1,success=0,failure=1,canonical_ids=0,results:
[错误 - code = NotRegistered]
MulticastResult(multicast_id=7574342191790679138,total=1,success=0,failure=1,canonical_ids=0,results: [[ error-code=NotRegistered ]]
类似的问题早前公布,但我没有发现任何满意的答复那里。
Similar question was posted earlier but i didn't find any satisfactory answer there.
推荐答案
为您在 devicesList
不与GCM注册提供设备的注册ID。首先,您需要将设备与GCM注册,以获得有效RegistrationId.After得到这个REGID你将它传递到服务器的话,只有你的服务器可以通过GCM推送通知。
The Registration Id for the device which you are providing in the devicesList
is not registered with the gcm.You first need to register your device with the gcm to obtain a valid RegistrationId.After getting this RegId You will pass it to server then,only your server can push the notification through GCM.
这篇关于notRegistered&QUOT;是什么错误由code&QUOT的意思;使用GCM发送推送消息时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!