简体   繁体   中英

Status bar notification icon not changing - API 23

I set up a ongoing notification with a foreground service. Here is the code.

NotificationCompat.Builder notificationBuilder= new NotificationCompat.Builder(this,"unique")
            .setSmallIcon(R.drawable.ic_mms_black_24dp)
            .setContentTitle("My notification")
            .setContentText("Hello World!")
            .setPriority(NotificationCompat.PRIORITY_DEFAULT);

    Notification notification= notificationBuilder.build();
    startForeground(MY_ID,notification);

But the icon that I have set at setSmallIcon() have no effect, instead it shows default app icon on status bar and notification panel which run on the Android 6. However After that I ran the above code on Android 5.1.1 (API LEVEL 22) and it shows the correct icon. I tried different types of icon (png,xml) and all worked well. But on my Marshmallow one It just shows the default app icon.

How do I figure out the reason?

From Android 6(Icon is at the left most corner):

从Android 6开始(图标在最左角

From Android 5(Icon is at the left most corner): 从Adroid 5

EDIT : I tried a white icon too. But still notification shows the default app icon. Is there any size constraints of the icon? But xml icons are scalable right.

It is most likely because your icon is black in color.

For latest Android versions, you need the notification icon to be white in color.

Status bar icons are composed simply of white pixels on a transparent backdrop

You could checkout the guidelines here - https://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar

Also make sure that you have all the correct sizes required by different screen densities as well.

It seems like issue is from manufacture of the OS. There is a issue in EMUI 4.0+ that doesn't show custom notification icons. It only shows the application default icon in the status bar. If your model has EMUI It is the issue. This guide might help to fix the issue - How to enable ui tuner EMUI 4 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM