Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Honeycomb notifications - How to set largeIcon to the right size?

I find myself curious why the setLargeIcon method on Notification.Builder only accepts a Bitmap, with no overload to provide a resource id. Perhaps it was done for performance reasons, but it seems odd as setSmallIcon does accept a res drawable id.

Notification.Builder builder = new Notification.Builder(application); // .... builder.setLargeIcon(iconBitmap);  // Requires a Bitmap builder.setSmallIcon(iconResId);   // Requires a drawable resource ID Notification notification = builder.getNotification(); 

Sadly the bitmap provided is not scaled in the notification, so the Bitmap needs to be provided exactly the right size for the notification view.

Assuming I need to provide xhdpi, hdpi, mdpi and ldpi versions of the largeIcon bitmap, what sizes do they need to be? I can see no mention in the docs, or after scouring the wider web.

like image 721
Ollie C Avatar asked Aug 28 '11 11:08

Ollie C


1 Answers

Not had a chance to check it yet but API 11 introduced the following public dimens:

  • notification_large_icon_height
  • notification_large_icon_width

Should be able to use those to scale your image before setting it on the notification.

like image 74
crafty Avatar answered Sep 21 '22 17:09

crafty