2017-07-11 4 views
0

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.

Antwort

1

Nachrichten, die über die REST-API gesendet werden, werden nicht in der Konsole angezeigt (unabhängig davon, ob sie an ein Token oder an ein Thema gesendet werden).

Wenn Sie die REST-API zum Senden an ein Token verwenden, können Sie dies normalerweise auf der Seite Diagnose anzeigen. Nachrichten, die an Themen gesendet werden, werden dort jedoch ebenfalls nicht angezeigt. (Siehe den möglichen doppelten Beitrag, den ich im Kommentarbereich verlinkt habe)

Verwandte Themen