gpt4 book ai didi

java - 推送通知模块发送 null

转载 作者:太空宇宙 更新时间:2023-11-04 12:54:12 28 4
gpt4 key购买 nike

我正在尝试使用 gcm 向注册设备发送通知。但它发送“null”而不是消息。我已经尝试了很多解决方案。如果缺少任何基本的东西,请分享。我已附上代码 spinet。

        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());

最佳答案

您使用的网址不正确。它应该是 https://gcm-http.googleapis.com/gcm/send。请参阅Server changes .

关于java - 推送通知模块发送 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35548612/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com