稍微改动一下,修改如下:
final PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = pm.getPackageArchiveInfo(fullPath, 0);//fullPath 为apk文件路径
Resources activityRes = mContext.getResources();
AssetManager assmgr = new AssetManager();
assmgr.addAssetPath(fullPath);//fullPath 为apk文件路径
Resources apkRes = new Resources(assmgr,
activityRes .getDisplayMetrics(),
activityRes .getConfiguration());
String label;Drawable icon;String packageName;
label = apkRes .getText(packageInfo.applicationInfo.labelRes).toString();//有可能为空
icon = apkRes .getDrawable(packageInfo.applicationInfo.icon);
packageName = packageInfo.packageName