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

后端 未结 2 644
醉梦人生
醉梦人生 2020-12-04 19:16

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 performan

相关标签:
2条回答
  • 2020-12-04 20:02

    I used the dimensions of the notification's large 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 the large icon with this scaled bitamp.

    0 讨论(0)
  • 2020-12-04 20:05

    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.

    0 讨论(0)
提交回复
热议问题