我正在开发一个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);
...
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);