2

I've a problem with the notification icon in android .

this is my code :

Notification myNotification = new NotificationCompat.Builder(ctx)
                .setSmallIcon(getNotificationIcon())
                .setAutoCancel(false).setContentTitle(onvan)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
                .setContentIntent(pending).build();

        long number = (long) Math.floor(Math.random() * 9000000000L) + 1000000000L;
        notificationManager.notify((int) number, myNotification);


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

What is the problem ?

sebenalern
  • 2,515
  • 3
  • 26
  • 36
naivd
  • 65
  • 5
  • 1
    What's the problem, exactly? You need to be specific. – Mike M. Jun 12 '16 at 05:32
  • @MikeM. the problem is in the picture ,as you can see there is an white square icon but I used another image as icon . – naivd Jun 12 '16 at 06:11
  • First of all, there's a white _circle_ in the image. Secondly, we don't know what your icon is supposed to be unless you tell us. – Mike M. Jun 12 '16 at 06:13
  • @MikeM. the icon I'm using is default android icon , not a circle white icon . – naivd Jun 12 '16 at 07:37

1 Answers1

1

Post android Lollipop release android has changed the guidelines for displaying notification icons in the Notification bar. The official documentation says "Update or remove assets that involve color. The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.” Now what that means in lay man terms is "Convert all parts of the image that you don’t want to show to transparent pixels. All colors and non transparent pixels are displayed in white"

You can see how to do this in detail with screenshots here https://blog.clevertap.com/fixing-notification-icon-for-android-lollipop-and-above/

Hope that helps

Rohit Khanna
  • 41
  • 1
  • 7