Android 获取未安装的app图标

六月ゝ 毕业季﹏ 提交于 2019-12-25 18:42:32
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);

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!