Notification icon modifies with closed app

Asked

Viewed 82 times

-1

When the App is open the icon appears normal, now when the app is not open only a circle appears instead of the icon. I have a system in Swing that when the user does a certain action is sent a notification.

Code that stays in the system in Swing

    public void enviaNotificacaoDenunciaFcm(String tkn, String corpo) {
    try {

        URL url = new URL("https://fcm.googleapis.com/fcm/send");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        conn.setUseCaches(false);
        conn.setDoInput(true);
        conn.setDoOutput(true);

        conn.setRequestMethod("POST");
        conn.setRequestProperty("Authorization", "key=chave do fcm");
        conn.setRequestProperty("Content-Type", "application/json");

        JSONObject json = new JSONObject();

        json.put("to", tkn);

        JSONObject info = new JSONObject();
        info.put("title", "Secretaria do Meio Ambiente");   // Notification title
        info.put("body", corpo); // Notification body
        info.put("color", "blue");

        json.put("notification", info);

        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(json.toString());
        wr.flush();
        conn.getInputStream();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "Erro ao enviar notificação!\n" + e, "Erro", JOptionPane.ERROR_MESSAGE);
        atualizaTabela();
        desabilitaBotoes();
        desabilitaCampos();
        limpaCampos();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "Erro ao enviar notificação!\n" + e, "Erro", JOptionPane.ERROR_MESSAGE);
    }

    // return null;
}

ao clicar no Salvar é enviada a Notificação

Notificação com App Aberto

Notificação com App Fechado

1 answer

0


just put the code below in Androidmanifest.xml, as per: https://vike.io/pt/408790/

 <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/ic_stat_name" />
        <meta-data android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/blue_dark" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.