Android Notification does not show color icon in Marshmallow

I am creating an application from which I get data from Parse and passing this data to Notification to generate and display it to the user.

But for some reason I can’t show the correct color icon in Marshmallows

On any other version of Android, its work is completely fine, but in Marshmallow its eerie white icon is not the actual one that I choose.

Here is my notification code.

  Intent cIntent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, cIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentText(data) .setContentTitle("Notification from Parse") .setContentIntent(pendingIntent); Notification notification = builder.build(); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(100, notification); 

Please help me with this or tell me how to get rid of this problem.

+5
source share
1 answer

First: Its not from Zephyr, the notification icon began to come out of BELL from the candy itself.

Checkout http://developer.android.com/design/style/iconography.html you will see that white style is how notifications should be displayed in Android Lollipop.

In Android Lollipop, Google also suggests that you use the color that will appear behind the notification icon (white) - https://developer.android.com/about/versions/android-5.0-changes.html

Second:. The solution to this problem is to install LargeIcon in the notification designer

 Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(largeIcon) .setContentText(data) .setContentTitle("Notification from Parse") .setContentIntent(pendingIntent); 

then your notification will look something like this:

setLargeIcon

You can also set the background color of the notification icon using .setColor() .

+19
source

Source: https://habr.com/ru/post/1236789/


All Articles