How to set the app icon as the notification icon in the notification drawer

93,802

Solution 1

Try this code at your notification builder :

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());

Set Large icon does the trick.Comment below if you have any further info

Solution 2

I know its bit late to answer here and also its already been answered, but I came here looking for an easy fix using firebase notifications. Someone like me visiting here can do the solution by recommended and easy way of firebase notification, which is simply adding meta-data in manifest.

Reference

<!-- 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" />
Share:
93,802
Aditya Suresh
Author by

Aditya Suresh

I love to code....I am the founder and CEO of Designox Studios

Updated on July 09, 2022

Comments

  • Aditya Suresh
    Aditya Suresh almost 2 years

    As shown in the figure...
    I am getting my notification icon(on left to the red colour).
    But I need to display the app icon as shown by the black arrow

    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());
    }
    
  • Manikanta
    Manikanta over 8 years
    Good, Add this line : .setLargeIcon(BitmapFactory.decodeResource(context.getResour‌​ces(), R.mipmap.ic_launcher))
  • Mansuu....
    Mansuu.... almost 7 years
    What if, app is not inforeground
  • Mansuu....
    Mansuu.... almost 7 years
    It shows both large icon and small icon, is there any way to remove small icon
  • Yogesh Maheshwari
    Yogesh Maheshwari over 6 years
    I don't see anything wrong with this code but interestingly, this code keeps crashing System UI in Nexus 5X with latest Android O. At first, I thought there was something wrong with the application that I was working with but then I created a new application and again the same thing. This looks like a major Android OS issue.
  • Curious Mind
    Curious Mind about 6 years
    Your answer was the most helpful. Thanks mate.
  • Lena Bru
    Lena Bru over 5 years
    how do you make this dynamic ?
  • Adam
    Adam over 5 years
    this declaration is also used for firebase default notification handling (when app is in killed state) for dynamic you can use custom in app notifications or modify firebase notifications. Have look at: stackoverflow.com/questions/37711082/…
  • Mu Sa
    Mu Sa over 5 years
    Helped me to change default icon for Push Notification Display Messages type.
  • Sumer Singh
    Sumer Singh about 5 years
    not working in 2019. help large icon is still gray circle with white transparent small icon
  • Arjun
    Arjun over 4 years
    Works fine. But the icon is towards the end of the notification. Is there a way to place the icon at the start of notification?
  • Arjun
    Arjun over 4 years
    How to set the large icon on the left side of the text in notification? Currently, I'm getting it on the right side of the text
  • Vrajesh Hirani
    Vrajesh Hirani over 4 years
    @Arjun this is the default behavior where the large icon is on the right hand side of the notifications. One can't really change the same but you can try using remote view through which you can create a custom notification layout and populate the same. With this, I think your use case would get catered.