Android 如何获取其他应用程序的通知图标?
在的帮助下,我正在使用NotificationListenerService捕获通知。但我无法提取图标的可绘制图像。我也在经历,但事情对我来说还不清楚。请提供帮助。要获取其他应用程序图标,只需获取该应用程序的软件包名称并使用以下代码即可。您将从通知实例获取包名Android 如何获取其他应用程序的通知图标?,android,android-notifications,android-notification-bar,Android,Android Notifications,Android Notification Bar,在的帮助下,我正在使用NotificationListenerService捕获通知。但我无法提取图标的可绘制图像。我也在经历,但事情对我来说还不清楚。请提供帮助。要获取其他应用程序图标,只需获取该应用程序的软件包名称并使用以下代码即可。您将从通知实例获取包名 String pack= "com.whatsapp" // ex. for whatsapp; Context remotePackageContext = null; Bitmap bmp = nul
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();
}
id来自何处?此处的“id”是可以从通知对象获取的图标资源id。例如:-Drawable Icon=remotePackageContext.getResources().getDrawable(notification.Icon);谢谢@SaadBinIqbal!重要注意事项:此代码应使用
statusbarnotificationstance.getNotification().icon
而不是statusbarnotificationstance.getId()
这将从应用程序中获取图标,而不是通知中显示的图标。