从apk文件中获取图标

时间:2013-06-13 03:48:05

标签: android winforms aapt

我正在开发一个Winform应用程序,使用aapt从apk文件中获取一些信息。我得到了应用程序图标的路径,如下所示:* res / drawable-mdpi / app_icon.png * 我想从其路径中获取图标并将其推送到ImageList。我该怎么做? 谢谢高级!

3 个答案:

答案 0 :(得分:6)

从APK文件获取图标:

File file = new File("/mnt/sdcard/thinkandroidsimple/pam.apk");
String sourcePath = file.getPath();

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

查看详情:How to get Icon from APK files in Android

答案 1 :(得分:0)

使用WinRar / WinZip或同等程序打开apk文件(就像.zip文件一样)并从该路径中提取文件。

答案 2 :(得分:0)

请参阅以下代码可能对您有所帮助

   public Drawable getFullResDefaultActivityIcon() {
            return getFullResIcon(Resources.getSystem(), android.R.mipmap.sym_def_app_icon);
        }

public Drawable getFullResIcon(Resources resources, int iconId) {
    Drawable d;
    try {
        ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
        int iconDpi = activityManager.getLauncherLargeIconDensity();
        d = resources.getDrawableForDensity(iconId, iconDpi);
    } catch (Resources.NotFoundException e) {
        d = null;
    }

    return (d != null) ? d : getFullResDefaultActivityIcon();
}

public Drawable getFullResIcon(String packageName, int iconId) {
    Resources resources;
    try {
        resources = mContext.getPackageManager().getResourcesForApplication(packageName);
    } catch (PackageManager.NameNotFoundException e) {
        resources = null;
    }
    if (resources != null) {
        if (iconId != 0) {
            return getFullResIcon(resources, iconId);
        }
    }
    return getFullResDefaultActivityIcon();
}

public Drawable getFullResIcon(ResolveInfo info) {
    return getFullResIcon(info.activityInfo);
}

public Drawable getFullResIcon(ActivityInfo info) {
    Resources resources;
    try {
        resources = mContext.getPackageManager().getResourcesForApplication(info.applicationInfo);
    } catch (PackageManager.NameNotFoundException e) {
        resources = null;
    }
    if (resources != null) {
        int iconId = info.getIconResource();
        if (iconId != 0) {
            return getFullResIcon(resources, iconId);
        }
    }
    return getFullResDefaultActivityIcon();
}

private Drawable getAppIcon(ResolveInfo info) {
    return getFullResIcon(info.activityInfo);
}