I'm using NotificationListenerService for catching notification, with the help of kpbird blog. But I'm unable to extract the icon's drawable. I'm also going through this, but things are not cleared to me. Please help.
Asked
Active
Viewed 2,683 times
1 Answers
3
To get other application icon, just get package name of that application and use below code. You will get package name from notification instance.
String pack= "com.whatsapp" // ex. for whatsapp;
Context remotePackageContext = null;
Bitmap bmp = null;
try {
remotePackageContext = getApplicationContext().createPackageContext(pack, 0);
Drawable icon = remotePackageContext.getResources().getDrawable(id);
if(icon !=null) {
bmp = ((BitmapDrawable) icon).getBitmap();
}
} catch (Exception e) {
e.printStackTrace();
}

Saad Bin Iqbal
- 65
- 7
-
where is id coming from? – Besnik Jun 17 '16 at 20:14
-
Here 'id' is Icon resource id that you can get from notification object. – Saad Bin Iqbal Jun 20 '16 at 04:46
-
1For example :- Drawable icon = remotePackageContext.getResources().getDrawable(notification.icon); – Saad Bin Iqbal Jun 20 '16 at 04:47
-
Thanks @SaadBinIqbal ! important to note that this code should use `statusBarNotificationInstance.getNotification().icon` and not `statusBarNotificationInstance.getId()` – Yoav Feuerstein Jan 25 '17 at 13:43
-
This will get the icon from the application, not the icon shown in the notification. – Denny Mar 01 '17 at 22:35