【问题标题】:phonegap-plugin-push message not showing for androidphonegap-plugin-push 消息未显示为 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 上实现多行通知。任何指针将不胜感激。

【问题讨论】:

    标签: ionic-framework push-notification ionic3


    【解决方案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

    【讨论】:

    • 难怪!事后看来,我不检查身体标签。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-07
    • 2011-12-09
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多