I'm trying to send a downstream push notification from the android client for practice only.
However, with this code:
private void send() {
String urlString = "https://fcm.googleapis.com/fcm/send";
JSONObject jsonObjects = new JSONObject();
try {
jsonObjects.put("title", titleET.getText().toString());
jsonObjects.put("body", textET.getText().toString());
} catch (JSONException e) {
e.printStackTrace();
}
RequestBody body = RequestBody.create(JSON, jsonObjects.toString());
Request req = new Request.Builder()
.url(urlString)
.post(body)
.addHeader("Authorization","key=censored")
.build();
try {
Response res = client.newCall(req).execute();
if (!res.isSuccessful()) {
throw new UnknownError("Error: " + res.code() + " " + res.body().string());
}
Log.d("MainActivity", res.body().toString());
} catch (IOException e) {
send();
}
}
As you can see, I'm not doing
jsonObjects.put("to","something");
That's because I don't want to send it to someone specifically, but to the whole application. If I don't put a "to" into the json, I get an error.
So, how can I send it to my whole application?