1
我想通過下面的代碼推送通知通過Java服務器發送到註冊設備:使用GCM發送推送消息時,錯誤代碼「notRegistered」意味着什麼?
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: [[ error-code=NotRegistered ]]
類似的質詢時被張貼,但我沒有」在那裏找到滿意的答案。
[GCM'Error:Not Registered']可能的重複(http://stackoverflow.com/questions/26718115/gcm-error-not-registered) – yennsarah
未註冊通常表示您的令牌(設備ID)正在使用無效。你應該丟棄它並生成另一個。 –