嗨,我的sd上有一个应用程序(不是安装在那里,只是存储在那里),我如何通过给出应用程序的路径来获取有关它的信息。例如,我的下载文件夹中有pandora.apk,所以路径是/sdcard/download/pandora.apk,知道该路径如何获得它的图标。谢谢你的帮助
我试过这段代码,但得到了一个nullpointerexception
final PackageManager pm = context.getPackageManager();
PackageInfo packageInfo = pm.getPackageArchiveInfo("/sdcard/download/pandora.apk", 0);
Drawable icOn = packageInfo.applicationInfo.loadIcon(context.getPackageManager());
最佳答案
这里已经有答案了。How to show icon of apk in my File manager
if (file.getPath().endsWith(".apk")) {
String filePath = file.getPath();
PackageInfo packageInfo = context.getPackageManager().getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
ApplicationInfo appInfo = packageInfo.applicationInfo;
if (Build.VERSION.SDK_INT >= 8) {
appInfo.sourceDir = filePath;
appInfo.publicSourceDir = filePath;
}
Drawable icon = appInfo.loadIcon(context.getPackageManager());
bmpIcon = ((BitmapDrawable) icon).getBitmap();
}
关于android - 获取SD卡上的应用程序图标,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8547692/