I am developing a APP
of sending PUSH
, from a APP
I could send a HTTP POST
to API
of firebase
, this means that when this message arrives at the API it is entrusted to send a PUSH
to all the nodes subscribed to a certain category.
The app
that I used is ARC
that is Chrome
. I would like to attach this to code Java
of android
, since I would like to send notifications from an activity of my App
and for that I have to send a HTTP POST REQUEST
with the data in JSON
. I leave you captures of how I do it with the APP
.
Yesterday I was a few hours and I could not manage to send a request from android
, today I have all morning and there is no way to work from android
.
FROM THE APP
OF THE PHOTOS I HAVE BEEN ABLE TO SEND THE PETITION AND EVERYTHING IS PERFECT:
I am using this code:
public void send_message() throws JSONException, IOException {
String authKey = "MI_API_KEY"; // You FCM AUTH key
String FMCurl = "https://fcm.googleapis.com/fcm/send";
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 item = new JSONObject();
String topic="/topics/POST";
item.put("Titulo_", "1");
item.put("Creador_", "2");
item.put("Cuerpo_", "3");
item.put("Fecha_", "4");
item.put("Tipo_", "5");
json.put("to", topic);
json.put("data", item);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(json.toString());
wr.flush();
conn.getInputStream();
}