Java 推送通知模块发送空
我正在尝试使用gcm向已注册的设备发送通知。但它发送“null”而不是消息。我试过很多解决办法。如果缺少任何基本的东西,请分享。我已附上代码spinetJava 推送通知模块发送空,java,android,push-notification,google-cloud-messaging,Java,Android,Push Notification,Google Cloud Messaging,我正在尝试使用gcm向已注册的设备发送通知。但它发送“null”而不是消息。我试过很多解决办法。如果缺少任何基本的东西,请分享。我已附上代码spinet JSONObject jGcmData = new JSONObject(); JSONObject jData = new JSONObject(); String msg = "new order came"; jData.put("message", msg);
JSONObject jGcmData = new JSONObject();
JSONObject jData = new JSONObject();
String msg = "new order came";
jData.put("message", msg);
// Where to send GCM message.
if (!(id == null)) {
jGcmData.put("to", id);
} else {
jGcmData.put("to", "/topics/global");
}
// What to send in GCM message.
jGcmData.put("data", jData);
// Create connection to send GCM Message request.
URL url = new URL("https://android.googleapis.com/gcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "key=" + API_KEY);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestMethod("POST");
conn.setDoOutput(true);
// Send GCM message content.
OutputStream outputStream = conn.getOutputStream();
outputStream.write(jGcmData.toString().getBytes());
您使用的url不正确。它应该是
https://gcm-http.googleapis.com/gcm/send
。请参阅。您使用的url不正确。它应该是https://gcm-http.googleapis.com/gcm/send
。请参阅。非常感谢您的有效回复。但仍然显示为空。非常感谢您的有效回复。但它仍然显示为空。