Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何获取其他应用程序的通知图标?_Android_Android Notifications_Android Notification Bar - Fatal编程技术网

Android 如何获取其他应用程序的通知图标?

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

在的帮助下,我正在使用NotificationListenerService捕获通知。但我无法提取图标的可绘制图像。我也在经历,但事情对我来说还不清楚。请提供帮助。

要获取其他应用程序图标,只需获取该应用程序的软件包名称并使用以下代码即可。您将从通知实例获取包名

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()
这将从应用程序中获取图标,而不是通知中显示的图标。