我正在开发一个安卓应用,我正在使用Firebase API通过HTTP POST在android工作室中发送推送通知。我按照这里的教程发送了标题和正文。它工作正常。我想发送额外的信息,请告诉我如何实现?这是我的代码:
...
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);
...
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);