The new Firebase notifications service allows us to use a Console UI to post notifications to all mobile app users.
But I could not find any REST API for the Fireba
@Narendra Naidu, Hi you can try this code snippet for server side push notification. create simple java class in your sever side project code and add this method with parameter you also need some firebase credential to do this. please try following.
// Method to send Notifications from server to client end.
public final static String AUTH_KEY_FCM = "ApidhfkIjd_cAdhpa-ZZ065hskiH53Hw3g";
public final static String API_URL_FCM = "https://fcm.googleapis.com/fcm/send";
// userDeviceIdKey is the device id you will query from your database
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("Authorization","key="+authKey);
conn.setRequestProperty("Content-Type","application/json");
JSONObject json = new JSONObject();
json.put("to",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();
}
Please go through this ref document:
it provides you server end information for sending notification from your server to - firebase server-to client application. Also, Find this below plain java code file (server end class) from which you will get some quick idea on same.
Please do let me know if I can be of further assistance.