Hier ist mein Code, den ich versuche, einen Firebase-Aufruf einzurichten, um eine Nachricht an ein Thema zu senden. Ich bekomme einen Antwortcode von 200 zurück, aber auf der FCM-Konsole wird nichts angezeigt. Mache ich etwas falsch.Firebase Cloud Messaging Thema
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();
}
Vielen Dank für die Hilfe im Voraus.