phonegap-plugin-push消息不显示为Android

时间:2019-01-24 07:50:00

标签: ionic-framework push-notification ionic3

我正在使用以下插件来通知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...");

对于Android:

    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 个答案:

答案 0 :(得分:1)

message更改为body

String pushMessage = "{\"priority\":\"high\",\"notification\":{\"title\":\"" +
            title +
            "\",\"body\":\"" +
            message +
            "\"},\"to\":\"" +
            DEVICE_TOKEN +
            "\"}";

有关格式,请参阅此处: enter image description here

https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support