web-dev-qa-db-fra.com

Comment définir l'icône de l'application en tant qu'icône de notification dans le tiroir de notification

Comme le montre la figure ...
Je reçois mon icône de notification (à gauche de la couleur rouge).
Mais je dois afficher l'icône de l'application comme indiqué par la flèche noire

enter image description here

    public void notify(View view){
    notification.setSmallIcon(R.drawable.ic_stat_name);
    notification.setTicker("Welcome to ****");
    notification.setWhen(System.currentTimeMillis());
    notification.setContentTitle("abcd");
    notification.setContentText("abcd");


    Intent intent = new Intent(this, home.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setContentIntent(pendingIntent);


    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(uniqueID, notification.build());
}
23
Aditya Suresh

Essayez ce code sur votre constructeur de notification:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
                        R.mipmap.ic_launcher))
                .setContentTitle(title)
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

Android.app.NotificationManager notificationManager =
                (Android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

Définissez une grande icône fait le tour.Commentaire ci-dessous si vous avez des informations supplémentaires

52
Manikanta

Je sais qu'il est un peu tard pour répondre ici et que cela a déjà été répondu, mais je suis venu ici pour trouver une solution facile en utilisant des notifications firebase. Quelqu'un comme moi qui visite ici peut faire la solution par un moyen simple et recommandé de notification par firebase, qui consiste simplement à ajouter des métadonnées dans un manifeste.

référence

<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
<meta-data
    Android:name="com.google.firebase.messaging.default_notification_icon"
    Android:resource="@drawable/ic_stat_ic_notification" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming notification message. -->
<meta-data
    Android:name="com.google.firebase.messaging.default_notification_color"
    Android:resource="@color/colorAccent" />
49
Adam