0

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);
    }
Suraj Makhija
  • 1,376
  • 8
  • 16
Panache
  • 1,701
  • 3
  • 19
  • 33

3 Answers3

4

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.

Aishwarya Tiwari
  • 625
  • 4
  • 19
  • So there I one main icon, then it has a circle in right bottom corner and a small white box in that. Setcolor set the color of circle from default Gray to color chosen though white box remain white. – Panache Apr 03 '17 at 15:11
  • There won't be any white box then, there will be a circle with the background color set & inside that will be your white icon that you created. – Aishwarya Tiwari Apr 03 '17 at 15:17
  • yes, actually I was using mipmap icon instead of drawable. Now I can see my small icon. – Panache Apr 03 '17 at 15:22
2

Use setSmallIcon(R.drawable.YOUR_SMALL_ICON) to set small icon for Notification.

FYI, According to the design guidelines you must use a silhouette for Builder.setSmallIcon(). See design gideline

Notification noti = new Notification.Builder(context)
            .setSmallIcon(getNotificationSmallIcon())
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.lnc))
            .setContentTitle("My Title")
            .setContentText("Done")
            .build();

..................
..........................

private int getNotificationSmallIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.drawable.ic_silhouette : R.drawable.ic_launcher;
}
Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61
0
        NotificationCompat.Builder mNotifyBuilder;

 mNotifyBuilder = new NotificationCompat.Builder(context)
                .setContentTitle("Captian Mansoura")
                .setContentText("Busy , On trip Now")
             .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.lnc))

                .setSmallIcon(R.mipmap.notify_offline);

try this

Elsunhoty
  • 1,609
  • 14
  • 27