您好我的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());
答案 0 :(得分:4)
它已在这里得到解答。 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();
}