Search code examples
javaandroidnotificationsnotification-icons

Add small icon in Notification Icon


I m using below code to get Notificaiton Icon. This give normal notification icon but there is small white box at the bottom right corner of it. How can I set icon for that too.

 public void not() {
        Notification noti = new Notification.Builder(context).setSmallIcon(R.mipmap.lnc)
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.lnc))
                .setContentTitle("My Title")
                .setContentText("Done").setSmallIcon(R.mipmap.lnc)
                .build();
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        // hide the notification after its selected
        noti.flags |= Notification.FLAG_AUTO_CANCEL;

        notificationManager.notify(0, noti);
    }

Solution

  • Lollipop onwards, your small icon must be monochrome i.e. transparent background & white color, otherwise it'll be displayed as a white box. So convert your R.mipmap.lnc into a silhouette i.e. create your icon in such a way that the parts you want to show should be white & the background be transparent. If you want to add a color to the background you can do it using setColor method.

    Read this link.