Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NotificationCompat.Builder setLargeIcon() not working?

Tags:

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.

like image 694
Matti Torvaldsson Avatar asked Mar 04 '16 15:03

Matti Torvaldsson


1 Answers

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"); 
like image 188
Salar Rastari Avatar answered Sep 22 '22 14:09

Salar Rastari