尝试从我的应用服务器向 GCM 服务器发送消息时,出现 java.lang.IllegalArgumentException 异常。在客户端注册成功。
import java.util.ArrayList;
import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.MulticastResult;
import com.google.android.gcm.server.Sender;
class Notify {
public static void main(String args[]) {
try {
Sender sender = new Sender(
"AIzaSyCd9HdSlq51nLzoqxMaFLsxWaoxxIz6-bU");
ArrayList<String> devicesList = new ArrayList<String>();
devicesList.add("APA91bFzbdNTf5CVsnSpkPJxMTCUCnjruluaerQcONQq9f20aaHw1CMNcVFgBsnLd6gUQT5TxrV2WY5WBw9U9u4Paj3dAXgRbaATc9a2Gp0voF3h5elX3Be0r3xw3Kun2HZT1m3D8L6IwCkXtTiILIfVasiKd2uN3w");
devicesList.add("APA91bFzbdNTf5CVsnSpkPJxMTCUCnjruluaerQcONQq9f20aaHw1CMNcVFgBsnLd6gUQT5TxrV2WY5WBw9U9u4Paj3dAXgRbaATc9a2Gp0voF3h5elX3Be0r3xw3Kun2HZT1m3D8L6IwCkXtTiILIfVasiKd2uN3w");
// use this line to send message with payload data
Message message = new Message.Builder()
.collapseKey("1")
.timeToLive(3)
.delayWhileIdle(true)
.addData("message",
"this text will be seen in notification bar!!")
.build();
// Use this for multicast messages
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) {
}
} else {
int error = result.getFailure();
System.out.println(error);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
那是代码
java.lang.IllegalArgumentException: argument cannot be null
at com.google.android.gcm.server.Sender.nonNull(Sender.java:553)
at com.google.android.gcm.server.Sender.getString(Sender.java:534)
at com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:365)
at com.google.android.gcm.server.Sender.send(Sender.java:261)
at com.example.server.Notify.main(Notify.java:34)
这就是我的问题