0

I have generated a local notification by this following code.

Notification notification = new Notification.Builder(context)
    .setAutoCancel(true)
    .setContentTitle("title")
    .setContentText("message")
    .setWhen(System.currentTimeMillis())
    .setSmallIcon(getNotificationIcon())
    .build();



private static int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.drawable.icon_loli : R.drawable.ic_launcher;
}

where icon icon_loli is 16*16 white icon. still for the api version below 21, it works very fine but on lollipop & above it will show a notification as in image below

enter image description here

Mohsin
  • 1,586
  • 1
  • 22
  • 44
  • Possible duplicate of [Notification bar icon turns white in Android 5 Lollipop](http://stackoverflow.com/questions/28387602/notification-bar-icon-turns-white-in-android-5-lollipop) – Gueorgui Obregon Feb 28 '16 at 06:03

1 Answers1

0

This is because of setSmallIcon(), and with the material design it is only black and white because the main purpose is to show uniformed icon into the top bar. If you want your logo, you will have to use setLargeIcon() like:

Notification notification = new Notification.Builder(context)
    .setAutoCancel(true)
    .setContentTitle("title")
    .setContentText("message")
    .setWhen(System.currentTimeMillis())
    .setSmallIcon(getNotificationIcon())
    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
    .build();
xiaomi
  • 6,553
  • 3
  • 29
  • 34
  • setLargeIcon() take the full scale logo of app as in api lvl below 20? – Mohsin Feb 28 '16 at 05:49
  • No problem. You should have use Large icon and Small icon from the beginning. The small for the status bar (design recommended to have a white icon, but before lollipop you can use whatever you want. But since Lollipop, the OS forces you to display only white small icon). The Large icon will keep the colored icon you input. – xiaomi Feb 28 '16 at 05:59
  • I have placed white icon. 16x16. it show me that notification icon as in image above, this is what my question was – Mohsin Feb 28 '16 at 06:01
  • The small icon is use as the image you've shown because there is no large icon. – xiaomi Feb 28 '16 at 06:08
  • what is recommended wxh for notification icon, with transparent bg? – Mohsin Feb 28 '16 at 06:11
  • Check the design guide line for more information https://www.google.com/design/spec/patterns/notifications.html#notifications-behavior – xiaomi Feb 28 '16 at 06:15
  • You don't need the `.setWhen(System.currentTimeMillis())` since it is the default behaviour. – Adib Faramarzi Oct 09 '17 at 18:32