开发者

How to show icon of apk in my File manager

开发者 https://www.devze.com 2023-02-24 19:58 出处:网络
I want to show icon of apk file in my listview. 开发者_运维知识库How can i get icon of apk?if (file.getPath().endsWith(\".apk\")) {

I want to show icon of apk file in my listview.

开发者_运维知识库How can i get icon of apk?


    if (file.getPath().endsWith(".apk")) {
        String filePath = file.getPath();
        PackageInfo packageInfo = context.getPackageManager().getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
        if(packageInfo != null) {
            ApplicationInfo appInfo = packageInfo.applicationInfo;
            if (Build.VERSION.SDK_INT >= 8) {
                appInfo.sourceDir = filePath;
                appInfo.publicSourceDir = filePath;
            }
            Drawable icon = appInfo.loadIcon(context.getPackageManager());
            bmpIcon = ((BitmapDrawable) icon).getBitmap();
        }
    }

The most important line is appInfo.publicSourceDir = filePath;

This is a bug. See http://code.google.com/p/android/issues/detail?id=9151

The null check packageInfo != null is there in case the .apk is not parsed correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号