Firebase通知的语法是什么?

时间:2016-12-13 13:49:47

标签: java firebase firebase-cloud-messaging

我想将firebase通知写为类似JSON格式的字符串..我已经发送了一个设备的通知但是当尝试发送到多个设备时,我得到了错误的请求..

params = new StringEntity("{\n" +
"    \"to\" : \"ds1YTh...UUZOos\",\n" +
"    \"notification\" : {\n" +
"      \"body\" : \""+jobTitle+"\",\n" +
"      \"title\" : \"New Job!\",\n" +
"      \"icon\" : \"hire\"\n" +
"      \"sound\" : \"default\"\n"+
"       \"time_to_live\" : "+3600+
"    }\n" +
"     \"data\": {"+
"     }"+
" }");

我怎么能这样做...如果我不能这样做,那么实现这个的最好方法是什么..我正在使用 HttpClient HttpPost 和primefaces 5.3

2 个答案:

答案 0 :(得分:0)

我在Asp.net做过,希望它能以某种方式帮助......

 for (int i = 0; i < dt.Rows.Count (No. of Rows or Device); i++)
            {
 tRequest.ContentType = "application/json";
            var data1 = new
            {
               to="" + DeviceID + "",
               priority="high",
                notification = new
                  {
                      body = Message,
                      is_background = true,
                      title = Heading,
                      appicon = "http://webbestsites.com/images/1_icon.png",
                      sound = "default"
                  },
  }

答案 1 :(得分:0)

首先是一些相关链接:

但是如果你想最接近你当前的代码,你应该能够在registration_ids属性中指定设备令牌:

params = new StringEntity("{\n" +
"    \"registration_ids\" : [\"ds1YTh...UUZOos\", \"et2ZUi...VVUPpt\"],\n" +
"    \"notification\" : {\n" +
"      \"body\" : \""+jobTitle+"\",\n" +
"      \"title\" : \"New Job!\",\n" +
"      \"icon\" : \"hire\"\n" +
"      \"sound\" : \"default\"\n"+
"       \"time_to_live\" : "+3600+
"    }\n" +
"     \"data\": {"+
"     }"+
" }");