public static Drawable getApkIcon(String Path)
{
String apkPath = Path; // apk 文件所在的路径
Drawable icon = null;
PackageManager pm = context.getPackageManager();
PackageInfo info = pm.getPackageArchiveInfo(apkPath ,PackageManager.GET_ACTIVITIES);
if (info != null) {
ApplicationInfo appInfo = info.applicationInfo;
appInfo.publicSourceDir = apkPath;//add-absolute path of app Drawable icon = pm.getApplicationIcon(appInfo);
icon = pm.getApplicationIcon(appInfo);
}
return icon;
}
网上也有这种方法但是获取失败了,无意间看到大神评论这是因为对于未安装应用ApplicationInfo未能获取到对应的source path。 只要在getApplicationIcon()前传入source path即可: appInfo.publicSourceDir = mFilePath;//add-absolute path of app Drawable icon = pm.getApplicationIcon(appInfo);
来源:CSDN
作者:性感菠萝头
链接:https://blog.csdn.net/wljs17/article/details/103694440