Android Notification is not showing Colour Icon in Marshmallow
Asked Answered
B

2

7

I am Making application is which i am getting data fromParse and transfering that data to Notification to generate and show it to user.

But for Some Reason I am unable to show correct Coloured Icon in Marshmallow

In every other Android Version its working totally fine, but in Marshmallow its creepy white icon not actual which i select.

Here is my Code of Notification.

 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 any other way how to get rid of this problem.

Bolide answered 25/11, 2015 at 10:24 Comment(0)
V
20

First : Its not from Marshmallow, Notification icon started turning out WHITE from Lollipop itself.

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

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

Second : Solution to this is setting LargeIcon to Notification Builder

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 color to background of Notification Icon by using .setColor().

Vanlandingham answered 25/11, 2015 at 10:47 Comment(6)
You are Awesome its WorkingBolide
But there is also the small icon in bottom right is there anyway to remove thatBolide
No, you can't because actually that icon will displayed in your Notification when your phone is locked and Notification appears.Vanlandingham
yea Great.. But my Boss seeing the Notification like Twitter and Facebook with Proper their icons. so they want me to do the same, can you help me with thisBolide
In Facebook and twitter they have applied setColor according to their respective theme color that is Dark blue for Facebook and Light Blue for Twitter. They are not using setLargeIcon.Vanlandingham
oh yea I get that Thank You So Much You are Amazing. Thank You So Much Again #RespectBolide
R
0

On some models (as Pixel and more), you can add only one color, just add:

.setColor(ContextCompat.getColor(context, R.color.your_color))

Residency answered 21/1, 2021 at 14:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.