Here is my code that I am attempting to set up a firebase call to send a message to a topic. I get a 200 response code back but nothing appears on the FCM console. Am i doing something wrong.
public static void pushFCMNotification() throws Exception{
String authKey = Constants.AUTH_KEY_FCM;
String FMCurl = Constants.API_URL_FCM;
URL url = new URL(FMCurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization","key="+authKey);
conn.setRequestProperty("Content-Type","application/json");
JSONObject json = new JSONObject();
JSONObject info = new JSONObject();
try {
info.put("title", "New notification"); // Notification title
info.put("body", "A new notification has been added to the notice board"); // Notification body
json.put("notification", info);
json.put("to", "/topics/notif"); //replace userDeviceIdKey with the unique notification key for the group
} catch (JSONException e) {
e.printStackTrace();
}
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(json.toString());
wr.flush();
conn.getInputStream();
}
Thanks for the help in advance.