Cell notifications. How to set largeIcon to the right size?

I'm curious why the setLargeIcon method in Notification.Builder accepts only Bitmap, without overloading to provide a resource identifier. This may have been done for performance reasons, but it seems strange since setSmallIcon accepts a res drawable identifier.

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(); 

Unfortunately, the provided bitmap does not scale in the notification, so Bitmap must be provided with exactly the right size for the notification.

Assuming I need to provide the xhdpi, hdpi, mdpi and ldpi versions of the Icon large bitmap, what sizes should they be? I do not see mention in the docs or after cleaning up a wider website.

+42
android android-3.0-honeycomb android-notifications
Aug 28 2018-11-11T00:
source share
2 answers

We did not have the opportunity to test it, but API 11 introduced the following sizes:

Must be able to use them to scale the image before setting it in the notification.

+57
Aug 28 2018-11-18T00:
source share

I used the dimensions of a large notification icon to create a scaled bitmap

 BitmapDrawable contactPicDrawable = (BitmapDrawable) ContactsUtils.getContactPic(mContext, contactId); Bitmap contactPic = contactPicDrawable.getBitmap(); Resources res = mContext.getResources(); int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height); int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width); contactPic = Bitmap.createScaledBitmap(contactPic, width, height, false); 

And then I set a big icon with this scaled bit.

+60
Jan 21 '13 at 18:38
source share



All Articles