Anroid push notifications , fcm

By Алмас Абдразак

I’m develop java rest api service and i need to make push notifications to anroid devices. I’m not really sure how to do it properly, my code is

public class FcmNotif {
    public final static String AUTH_KEY_FCM = "My key";
    public final static String API_URL_FCM = "";
// userDeviceIdKey is the device id you will query from your database
    public void pushFCMNotification(String userDeviceIdKey, String title, String message) 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.setRequestProperty("Authorization", "key=" + authKey);
        conn.setRequestProperty("Content-Type", "application/json");
        JsonObject json = new JsonObject();
        json.addProperty("to", userDeviceIdKey.trim());
        JsonObject info = new JsonObject();
        info.addProperty("title", title); // Notification title
        info.addProperty("body", message); // Notification body
        info.addProperty("image", "");
        info.addProperty("type", "message");
        json.add("data", info);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
       // System.out.println(url.getH);
    public static void main(String[] args) throws Exception {
        FcmNotif fcmN=new FcmNotif();
        fcmN.pushFCMNotification("user id ", "myFirstMessage", "hello");

AUTH_KEY_FCM i get from “Server API Key” and userDeviceIdKey its id that i get from running this code in android studio

String android_id = Settings.Secure.getString(getApplicationContext().getContentResolver(),

Maybe i don’t understand smth clearly, whan am i doing wrong?

Source: Stack Overflow


Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273