phonegap-plugin-push 消息未显示为 android
Posted
技术标签:
【中文标题】phonegap-plugin-push 消息未显示为 android【英文标题】:phonegap-plugin-push message not showing for android 【发布时间】:2019-01-24 07:50:00 【问题描述】:我正在为 Ionic 3 的通知使用以下插件。
<plugin name="phonegap-plugin-push" spec="1.10.5">
对于 ios,我可以通过在我的后端使用它来实现多行:
private static String iosMessage = "Test Alert Header\nTest Message";
ApnsService service =
APNS.newService()
.withCert(PATH_TO_P12_CERT, CERT_PASSWORD)
.withProductionDestination()
.build();
String payload = APNS.newPayload()
.alertBody(iosMessage)
.sound("default")
.build();
service.push(DEVICE_TOKEN, payload);
System.out.println("The message has been sent...");
对于安卓:
private static String title = "Message Header";
private static String message = "Message Text";
String pushMessage = "\"priority\":\"high\",\"notification\":\"title\":\"" +
title +
"\",\"message\":\"" +
message +
"\",\"to\":\"" +
DEVICE_TOKEN +
"\"";
// Create connection to send FCM Message request.
URL url = new URL("https://fcm.googleapis.com/fcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "key=" + SERVER_KEY);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestMethod("POST");
conn.setDoOutput(true);
// Send FCM message content.
OutputStream outputStream = conn.getOutputStream();
outputStream.write(pushMessage.getBytes());
System.out.println(conn.getResponseCode());
System.out.println(conn.getResponseMessage());
我无法显示仅“消息标题”出现在单行通知中的“消息文本”。
我正在尝试在 android 上实现多行通知。任何指针将不胜感激。
【问题讨论】:
【参考方案1】:将message
更改为body
:
String pushMessage = "\"priority\":\"high\",\"notification\":\"title\":\"" +
title +
"\",\"body\":\"" +
message +
"\",\"to\":\"" +
DEVICE_TOKEN +
"\"";
格式参考这里: https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support
【讨论】:
难怪!事后看来,我不检查身体标签。谢谢!以上是关于phonegap-plugin-push 消息未显示为 android的主要内容,如果未能解决你的问题,请参考以下文章