我想從服務器獲取消息作爲android中的推送通知。我能夠擊中服務器,但我從服務器收到空消息。我可以在android中看到沒有消息的通知。 這是從服務器我的代碼和我的Android代碼ANDROID HIVEGCM給出空消息
public class GCMBroadcast {
@POST
@Path("/getgcm")
public String getGcmData(){
String str="success";
try {
System.out.println("From CLient");
Sender sender = new Sender(
"AIzaSyBbfXkbCYWQdE5qyjJKwl-YLBX-F01ICug");
// add your own google api key in android menifest
// use this to send message with payload data
Message message = new Message.Builder()
.collapseKey("message")
.timeToLive(3)
.delayWhileIdle(true)
.addData("message", "Welcome to Push Notifications")
// you can get this message on client side app
.build();
System.out.println("message:"+message);
System.setProperty("http.proxyHost", "192.168.1.110");
// write you own proxy
System.setProperty("http.proxyPort", "8080");
// write you own proxy host
// Use this code to send notification message to a single device
Result result = sender
.send(
message,
"APA91bFEmQ53TKnJQXa0HbF9lXGTMEyRrp-6H9-_zZNBdFAUMsvXIG0rpvKcXn_6L5wBP77HskWw4svo6GLHZwfWdDf-yQCBAvIqp4fQF05cWqDtJ8mfNDnAQ8qdXByaEqwDmK3aQi0xIq7L3XGF1dSkbOOfBFIjlfDzlj4SG3z_SA-v3IUz_g4",
1);
System.out.println("Message Result: " + result.toString());
// Use this code to send notification message to multiple
// devices
/*ArrayList<String> devicesList = new ArrayList<String>();
// add your devices RegisterationID, one for each device
devicesList
.add("APA91bFEmQ53TKnJQXa0HbF9lXGTMEyRrp-6H9-_zZNBdFAUMsvXIG0rpvKcXn_6L5wBP77HskWw4svo6GLHZwfWdDf-yQCBAvIqp4fQF05cWqDtJ8mfNDnAQ8qdXByaEqwDmK3aQi0xIq7L3XGF1dSkbOOfBFIjlfDzlj4SG3z_SA-v3IUz_g4");
// Use this code for multicast messages
MulticastResult multicastResult = sender.send(message,
devicesList, 0);
sender.send(message, devicesList, 0);
System.out.println("Message Result: "
+ multicastResult.toString());
*/
} catch (Exception e) {
e.printStackTrace();
str="Failure";
}
return str;
}
}
假設你從谷歌的成功響應,你應該張貼的處理的應用程序代碼該消息是否需要幫助查找問題。 – Eran
我從[this]獲取了應用程序代碼(http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/),並從android樣品 –