获得Android APK图标的代码
jopen
12年前
public static Drawable getApkIcon(String path, Context mContext) { Drawable icon = null; try { String apkPath = path; PackageParser packageParser = new PackageParser(apkPath); DisplayMetrics metrics = new DisplayMetrics(); metrics.setToDefaults(); PackageParser.Package mPkgInfo = packageParser.parsePackage( new File(apkPath), apkPath, metrics, 0); ApplicationInfo info = mPkgInfo.applicationInfo; Resources pRes = mContext.getResources(); AssetManager assmgr = new AssetManager(); assmgr.addAssetPath(apkPath); Resources res = new Resources(assmgr, pRes.getDisplayMetrics(), pRes.getConfiguration()); if (info.icon != 0) { icon = res.getDrawable(info.icon); // bitmap = MyUtil.drawableToBitmap(icon); } packageParser = null; metrics = null; mPkgInfo = null; info = null; pRes = null; assmgr = null; res = null; } catch (Exception e) { icon = null; } return icon; }