1

I have an issue regarding the Notification with android 9, Notification icon is not showing with Android 9. I have use below code for show the icon with notification.

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    notificationBuilder.setSmallIcon(R.drawable.ic_notify);
    /* Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_notify);
    notificationBuilder.setLargeIcon(icon);*/
    notificationBuilder.setColor(getResources().getColor(R.color.colorWhite));
} else {
    notificationBuilder.setSmallIcon(R.drawable.ic_notify);
}
Jakir Hossain
  • 3,426
  • 1
  • 11
  • 25

2 Answers2

1

Finally i have found the solution(With Android 9)

Step 1: Your image will be white with transparent background.

Step 2: You have set the background color according to your app icon.

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

           notificationBuilder.setSmallIcon(R.mipmap.ic_appoint);// this is the white image with transparent background
            notificationBuilder.setColor(getResources().getColor(R.color.colorGreen));
        } else {
            notificationBuilder.setSmallIcon(R.drawable.ic_notify); // this is normal image 
        }
0
Implementation of `Notification Builder` for below and above Lollipop OS version would be:


NotificationCompat.Builder notificationBuilder = new 
NotificationCompat.Builder(this);

notificationBuilder.setSmallIcon(getNotificationIcon(notificationBuilder));

private int getNotificationIcon(NotificationCompat.Builder 
notificationBuilder) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
         int color = 0x008000;
         notificationBuilder.setColor(color);
         return R.drawable.app_icon_lolipop_above;

 } 
 return R.drawable.app_icon_lolipop_below;
 }
MurugananthamS
  • 2,233
  • 4
  • 16
  • 47