I would like to send a message to an Android mobile with GCM (Google Cloud Message). But when the process goes to Sender sender = new Sender(serverKey);
the process stopped but there is no exception thrown. It seems that issue happends when create an instance of Sender, but it does not throw any exception outside.
How can I get the exception information? The serverKey is correct. Why this sentence has error?
@Override
public void sendMessage(String msg) {
try {
String serverKey = "aaaa";
String regId = "xxxxxx";
Sender sender = new Sender(serverKey);
Message message = new Message.Builder().addData("msg", msg).build();
Result result = sender.send(message, regId, 5);
String status = "Sent message to one device: " + result;
System.out.println(status);
} catch (Exception e) {
e.printStackTrace();
}
}
The Sender
class has only one constructor, and here is its code:
public Sender(String key) {
this.key = nonNull(key);
}
The only way this constructor can throw an exception is if you pass it a null
key (which will result in IllegalArgumentException
).
Therefore, either you are passing null
to that constructor or you are not getting any exception in that line.
Actually, another option is that your process has no access to gcm-server.jar
, which contains the Sender
class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.