Notification thumbnails

NotificationCompat is a neat way to take advantage of the rich notification features introduced in Honeycomb and JellyBean without worrying about older platform versions. The thumbnail image is expected as a Bitmap, though, so there is a bit of code to write if you want to fetch these images from a server or resize them to fill the available space.

ImageLoader provides a utility for downloading Bitmaps in this scenario (it’s synchronous, you need to handle threading yourself):

Bitmap thumbnail = new DirectLoader().download(url)

If your thumbnail isn’t exactly the right size, here’s a helper class that I threw together to scale and crop a Bitmap to the dimensions expected by the notification tray.

Bitmap scaled = new NotificationThumbnailHelper(context).scaleBitmap(thumbnail)