Reputation: 836
I'm trying to retrieve the small icon of a Notification inside the
NotificationListenerService
.
I've found the notification.getSmallIcon()
function that return a android.graphics.drawable.Icon
. How it's possible to obtain a Bitmap
from that Icon?
Upvotes: 1
Views: 1342
Reputation: 2594
You need to use loadDrawable
or loadDrawableAsync
on the icon it will return a drawable.
loadDrawable
added in API level 23public Drawable loadDrawable
(Context context)
Returns aDrawable
that can be used to draw the image inside this Icon, constructing it if necessary. Depending on the type of image, this may not be something you want to do on the UI thread, so consider using loadDrawableAsync instead.
as shown below
Icon icon = notification.getSmallIcon();
Bitmap bitmap = icon.loadDrawable(context);
then you can convert the drawable to bitmap from the stackoverflow link below there are many answers how to convert drawable to Bitmap
How to convert a Drawable to a Bitmap?
Upvotes: 4