我正在开发一个使用 aapt 从 apk 文件中获取一些信息的 Winform 应用程序。我得到了应用程序图标的路径,如下所示: *res/drawable-mdpi/app_icon.png* 我想从其路径中获取图标并将其推送到 ImageList。我该怎么做?感谢先进!
问问题
3274 次
3 回答
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();
}
}
于 2014-03-31T07:50:04.163 回答
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);
}
于 2013-06-13T03:59:53.593 回答
0
使用 WinRar/WinZip 或等效软件打开 apk 文件(就像打开 .zip 文件一样)并从该路径中提取文件。
于 2013-06-13T03:53:00.793 回答