Why is my notification icon not displayed properly

2019-07-13 18:02发布

问题:

We have notifications in our app since a long time, which work fine. I have a small, multicoloured .png-icon we use for them, that have worked fine in the past.

In Oreo, the icon is not displayed properly, it is just a grey square. Looking at the drawer on the device, it seems that the system, gmail etc. all now have single-colour icons, so i suspect that it has something to do with that.

However, i can't find any documentation, design guidelines or anything that confirm this, so i am surrendering to a question here...

How can i make my icon display as normal in Oreo? What am i missing?

This is how i create the icon, from what i can see in documentation it should work, and it works pre-Oreo:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

builder.setAutoCancel(true).setContentTitle("Title").setWhen(when)
.setContentText(message).setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon("icon.png").setContentIntent(contentIntent);

getNotificationManager(context).notify(NOTIFICATION_ID, builder.build());

回答1:

refer this https://developer.android.com/about/versions/android-5.0-changes.html after 5.0 it may change your icon due to this.