I want to send request to Firebase url with json object data and headers from my activity ,
I have checked the url from rest client and i am at success there , i am receiving correct response , but when i call this from android i am unable to get response:
here is my code:
public static void pushFCMNotification(String userDeviceIdKey) throws Exception{
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("Content-Type","application/json");
conn.setRequestProperty("Authorization","key="+authKey);
Log.e("authkey==> ",authKey+"");
JSONObject json = new JSONObject();
json.put("to",userDeviceIdKey.trim());
Log.e("deviceidkey==> ",userDeviceIdKey.trim()+"");
JSONObject info = new JSONObject();
info.put("title", "Notificatoin Title"); // Notification title
info.put("body", "Hello Test notification"); // Notification body
json.put("notification", info);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(json.toString());
wr.flush();
conn.getInputStream();
}
this is the json structure i want to send with url
i got no exception and on success of this request i should get a notification on my device , which is hapening from rest client but not from android ,
kindly check where i am making a mistake and how can check response of my request
