NotificationCompat.Builder setLargeIcon() not working?

Matti Torvaldsson picture Matti Torvaldsson · Mar 4, 2016 · Viewed 20.7k times · Source

When I add the code mNotificationBuilder.setLargeIcon(BitmapFactory.decodeResource( getResources(), R.drawable.ic_large_icon)); to my notification it stops working without errors or warnings. This only happens on pre-Lollipop, on Lollipop and beyond it works great. And with "works" I mean that the notification shows up.

My sample code:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

mBuilder.setSmallIcon(R.drawable.icon);
mBuilder.setContentTitle("Content Title");
mBuilder.setContentText("Content Text");
mBuilder.setLargeIcon(BitmapFactory.decodeResource( getResources(), R.drawable.ic_large_icon));

startForeground(1, mBuilder.build());

I have tried to load the Bitmap in different ways but it keeps failing... The icon is 128x128 so the size of it should not be a problem?

I have also tried different id's but none that solves the problem.

I would be so greatful of any advice, please any push in the right direction would mean the world to me.

EDIT 1#

This notification is issued from a Service. The service is alive and Log prints tell me that code after "startForeground()" is run.

Answer

Salar Rastari picture Salar Rastari · Jun 23, 2016

You have to first set large icon then small icon.

in my case this code is working:

    mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_message));
    mBuilder.setSmallIcon(R.mipmap.ic_message);
    mBuilder.setContentTitle("Inbox");
    mBuilder.setContentText("New message received");