Hi, I'm trying to send a firebase message from java code, and I did it from the console and its work, and I get a notification on my devices, and also sent messages via java to certain devices through a token and its work too, and I get Problems with sending to topics, I do not receive errors and exceptions from the server, but nothing was received on devices. here is the code i use to send firebase requests:
String authKey = AUTH_KEY_FCM; // You FCM AUTH key String FMCurl = 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(); json.put("to","/topics/all"); JSONObject data = new JSONObject(); data.put("message",title); json.put("data", data); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(json.toString()); wr.flush(); conn.getInputStream(); }
since you can see that the internal object in Json is Data with the “message” parameter, like the one specified in google docs, I also tried replacing it with a “notification” with “body” and “name” as its working to send messages to certain devices through a token, but again does not work for topics. and again it doesn’t need to be mentioned that everything on the Android side works because it works by sending a Subject message through the firebase console.
UPDATE: this method works, and I have to process it to actually show a notification when a message is received.
Thanks for your help in advance.
source share