0

I want to write the firebase notification as a String like JSON format .. I already sent the notification for one device but when trying to send to multiple devices i got bad request ..

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\": {"+
"     }"+
" }");

how could i do that .. and if I can't do it this way what is the best way to implement this .. I'm using HttpClient and HttpPost and primefaces 5.3

m 1987
  • 153
  • 2
  • 14
  • You're using `to` but you intend to send to multiple devices. Have you tried using `registration_ids`? See this [answer](http://stackoverflow.com/a/39547590/4625829). – AL. Dec 13 '16 at 14:50

2 Answers2

0

I have done it in Asp.net I hope it will help in some way...

 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"
                  },
  }
Vipin G
  • 169
  • 1
  • 8
0

First a few relevant links:

But if you want to stick closest to your current code, you should be able to specify the device tokens in a registration_ids property:

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\": {"+
"     }"+
" }");
Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807