如何在我的文件管理器中显示 apk 的图标 [英] How to show icon of apk in my File manager
本文介绍了如何在我的文件管理器中显示 apk 的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的列表视图中显示 apk 文件的图标.
I want to show icon of apk file in my listview.
如何获取apk的图标?
How can i get icon of apk?
推荐答案
if (file.getPath().endsWith(".apk")) {
String filePath = file.getPath();
PackageInfo packageInfo = context.getPackageManager().getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
if(packageInfo != null) {
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();
}
}
最重要的一行是appInfo.publicSourceDir = filePath;
这是一个错误.请参阅 http://code.google.com/p/android/issues/detail?id=9151
This is a bug. See http://code.google.com/p/android/issues/detail?id=9151
空检查 packageInfo != null
是否存在,以防 .apk 未正确解析.
The null check packageInfo != null
is there in case the .apk is not parsed correctly.
这篇关于如何在我的文件管理器中显示 apk 的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文