Android 从 apk 文件中提取应用程序图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12640359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Extract app icon from apk file
提问by www.jensolsson.se
I am in need of extracting the app icon from an apk-file. I just need one icon, i don't want to extract everything else in the apk. The files are easy to get hold on, but how do I determine which icon file is the correct app-icon. I guess this is stored in the resource table? So I guess what I need is actually to read the resource table and I hope that from the resource table I can determine the icon file namne which I can then extract from the app.
我需要从 apk 文件中提取应用程序图标。我只需要一个图标,我不想提取 apk 中的所有其他内容。这些文件很容易掌握,但我如何确定哪个图标文件是正确的应用程序图标。我猜这是存储在资源表中?所以我想我实际上需要的是读取资源表,我希望从资源表中我可以确定可以从应用程序中提取的图标文件 namne。
I need a simple tool for this, i know about apktool that can extract the entire apk file but this is not what I want since
我需要一个简单的工具,我知道可以提取整个 apk 文件的 apktool 但这不是我想要的,因为
it does a lof of other stuff that I dont need (decompile, decompress other files etc)
it takes a lot of time to run
它做了很多我不需要的其他东西(反编译、解压其他文件等)
运行需要很多时间
Is there any other tool I can use just to get hold of the icon file path?
有没有其他工具可以用来获取图标文件路径?
All suggestions are appreciated
感谢所有建议
EDIT: To clarify, I am not trying to do this on the device. I am trying to do this on a PC.
编辑:澄清一下,我不是要在设备上执行此操作。我正在尝试在 PC 上执行此操作。
回答by
aapt
tool ships with Android SDK, found under platform-tools
should give you the details you need. apktool ships with aapt.
aapt
工具随 Android SDK 一起提供,在下面找到platform-tools
应该为您提供所需的详细信息。apktool 附带 aapt。
aapt d --values badging payload.apk
aapt d --values badging payload.apk
Using this output, you can extract the icon file out of apk (which is a zip file).
使用此输出,您可以从 apk(这是一个 zip 文件)中提取图标文件。
回答by adrianTNT
- Rename the .apk file to .zip
- Unzip it with a tool like 7zip
- Find the icons as png files under:
/res/drawable-hdpi/icon.png
- 将 .apk 文件重命名为 .zip
- 用 7zip 之类的工具解压
- 在以下位置找到作为 png 文件的图标:
/res/drawable-hdpi/icon.png
Edit: Note that this file is not present in all apk files but in most of them. I could not find a better solution besides extracting all .png files and picking one from the list.
编辑:请注意,此文件并非存在于所有 apk 文件中,而是存在于大多数 apk 文件中。除了提取所有 .png 文件并从列表中选择一个之外,我找不到更好的解决方案。
回答by Dipak Sonnar
//if your apk is not installed ..only having .apk on sdcard
String APKFilePath = "mnt/sdcard/myapkfile.apk"; //For example...
PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(APKFilePath, 0);
// the secret are these two lines....
pi.applicationInfo.sourceDir = APKFilePath;
pi.applicationInfo.publicSourceDir = APKFilePath;
//
Drawable APKicon = pi.applicationInfo.loadIcon(pm);
String AppName = (String)pi.applicationInfo.loadLabel(pm);
you can refer this link
你可以参考这个链接
回答by Ridcully
As to my knowledge (and according to Wikipedia as well), APK files are ZIP file formatted packages. So I think you can just use any unzip tool to unzip the apk-file and take the icon you want. For the launcher-icon, just open the AndroidManifest.xml
file and have a look at the android:icon
property of the <application>
. It probably looks something like so:
据我所知(以及根据维基百科),APK 文件是 ZIP 文件格式的包。所以我认为你可以使用任何解压缩工具来解压缩 apk 文件并获取你想要的图标。对于启动图标,只需打开AndroidManifest.xml
文件,并有一个看android:icon
的财产<application>
。它可能看起来像这样:
android:icon="@drawable/ic_launcher"
android:icon="@drawable/ic_launcher"
The icon file would then be res/drawable-<dim>/ic_launcher.png
, where <dim>
can be any of ldpi, mdpi, hdpi, xhdpi
which stand for different resolutions. The largest image would be in xhdpi
or hdpi
.
图标文件将是res/drawable-<dim>/ic_launcher.png
,其中<dim>
可以是ldpi, mdpi, hdpi, xhdpi
代表不同分辨率的任何一个。最大的图像将在xhdpi
或 中hdpi
。
回答by kefir500
Software
软件
You can also try these GUI tools to easily extract Android app icon:
您还可以尝试使用这些 GUI 工具轻松提取 Android 应用程序图标:
- APK Icon Editor– simple and intuitive.
- APK Editor Studio– more advanced but still easy to use.
- APK 图标编辑器- 简单直观。
- APK Editor Studio– 更先进但仍然易于使用。
Description
描述
Though the Apktool is used under the hood, the GUI front-end makes it very simple to extract or change APK icons.
尽管 Apktool 是在幕后使用的,但 GUI 前端使得提取或更改 APK 图标变得非常简单。
The proper application icons are automatically parsed from the manifest and the internal structure, so there is no need to manually search for the needed resource files.
正确的应用程序图标会自动从清单和内部结构中解析出来,因此无需手动搜索所需的资源文件。
- Both tools help you to easily edit, replace or extract iconsvia user-friendly GUI.
- Both tools are available for Windows, macOSand Linux.
- Both tools are open-source(written in C++/Qt).
- 这两种工具都可以帮助您通过用户友好的 GUI轻松编辑、替换或提取图标。
- 这两种工具都适用于Windows、macOS和Linux。
- 这两个工具都是开源的(用 C++/Qt 编写)。
Disclaimer
免责声明
I am the author of these tools.
我是这些工具的作者。
回答by JohnnyLambada
This bash
function will extract the icon and display it with preview
. If you're not on a mac, then you could use the display
command from ImageMagick.
此bash
函数将提取图标并用 显示它preview
。如果您不在 Mac 上,则可以使用ImageMagick 中的display
命令。
preview-android-icon () { unzip -p $(aapt d --values badging | sed -n "/^application: /s/.*icon='\([^']*\).*//p") > /tmp/$$.png && preview /tmp/$$.png; }
Use it like this:
像这样使用它:
preview-android-icon /path/to/your.apk
回答by Joe
if you are novice like me you can use android app Called My APK (Google Play Link) to extract apps icons on your android phone either this app installed or you just have downloaded the apk files from outsources like apkMirror, APKpure, AppsAraby
如果您像我一样是新手,您可以使用名为我的 APK(Google Play 链接)的 android 应用程序在您的 android 手机上提取应用程序图标,要么安装此应用程序,要么您刚刚从apkMirror、APKpure、AppsAraby等外包下载了 apk 文件
回答by mah
apktool's source is available. Since resource extraction and code decompilation are quite different, I suspect it would be easy to modify it to remove code decompilation to minimize it to what you need.
apktool 的源代码可用。由于资源提取和代码反编译是完全不同的,我怀疑修改它以删除代码反编译以将其最小化到您需要的内容会很容易。
As to determining the icon file name, you base that on the contents of AndroidManifest.xml, but you may need to account for multiple versions of the icon based on screen density, orientation, language configuration, etc.
至于图标文件名的确定,根据AndroidManifest.xml的内容确定,但可能需要根据屏幕密度、方向、语言配置等考虑图标的多个版本。