使用Android中的JSONObject向“额外信息”发送Firebase API通知

问题描述 投票:0回答:1

我正在开发一个Android应用程序,我正在使用Firebase API在Android工作室使用HTTP POST发送推送通知。我按照教程here发送标题和正文。它工作正常。我想发送额外的信息,请建议我如何实现?这是我的代码:

            ...

            JSONObject json = new JSONObject();                                                                     
            json.put("to", "/topics/" + "Greetings");

            JSONObject info = new JSONObject();
            info.put("title", "Hi");
            info.put("body", "Good morning");
            json.put("notification",info);

            JSONObject data = new JSONObject();
            data.put("extra_information", PreferenceUtils.getUserID());
            json.put("extra_information", data);

            ...
android json firebase firebase-cloud-messaging http-post
1个回答
0
投票

Firebase json有效负载如下所示:

[
    "to" => 'DEVICE_TOKEN',
    "notification" => [
        "body" => "SOMETHING",
        "title" => "SOMETHING",
        "icon" => "ic_launcher"
    ],
    "data" => [
        "ANYTHING EXTRA HERE"
    ]
]

使用以下内容进行额外操作。

JSONObject extras = new JSONObject();
extras.put("message", "Happy birthday!");
extras.put("userId", PreferenceUtils.getUserID());
json.put("data",extras);
© www.soinside.com 2019 - 2024. All rights reserved.