Android 中获取未安装APK的 图标 || icon

效果图,这是Android 系统自带的一个APK,专门管理文件下载功能,当然现在呈现在各位面前的是已经被我改的面目全非。

Android 自带的 下载 APK 并没有显示未安装APK图标的功能,而是用一个默认图标,现在这个功能在此项目中需要

开发,先看效果图


核心代码

// path 为 要获取APK 图标的 路经。

public Drawable getUnInstallIcon(Context context, String path){

Drawable icon = null;

PackageParser packageParser = new PackageParser(path);

File sourceFile = new File(path);

DisplayMetrics metrics = new DisplayMetrics();

metrics.setToDefaults();

PackageParser.Package pkg = packageParser.parsePackage(sourceFile,path,metrics,0);

if(null != pkg){

ApplicationInfo info = pkg.applicationInfo;

Resources pRes = mContext.getResources();

AssetManager assmgr = new AssetManager();

assmgr.addAssetPath(path);

Resources res = new Resources(assmgr,pRes.getDisplayMetrics(), pRes.getConfiguration());

if(info.icon != 0){

icon = res.getDrawable(info.icon);

}

}

return icon;

}

此代码放在这里,希望对有需者提供帮助。

猜你喜欢

转载自blog.csdn.net/qijian0503/article/details/39002443