10

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.

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

  • 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.

www.jensolsson.se
  • 3,023
  • 2
  • 35
  • 65
  • Actually you an get the app icon as drawable programmatic after that you can convert it to bitmap and save it to your device memory. – Dharmendra Sep 28 '12 at 12:59
  • @dharmendra, I am actually trying to do this on a web service, not on the actual device. I will clarify this in the question – www.jensolsson.se Oct 01 '12 at 13:14

8 Answers8

13

aapt tool ships with Android SDK, found under platform-tools should give you the details you need. apktool ships with aapt.

aapt d --values badging payload.apk

Using this output, you can extract the icon file out of apk (which is a zip file).

12
  • 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

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.

adrianTNT
  • 3,671
  • 5
  • 29
  • 35
  • This is not the correct solutions since you cannot determine the icon name and there can be many icons in an app. icon.png does not necessarily mean it is the app icon. – www.jensolsson.se Feb 04 '13 at 10:42
  • 1
    Yes, I edited my answer. I think there isn't a way to find the right one; for my personal use, I extract all files on server and list all .png files, then I select one of them. – adrianTNT Feb 05 '13 at 14:37
  • 1
    I found icon in `/res/mipmap-xxxhdpi-v4/icon.png`, in `/res/drawable-hdpi/` only contains splash image (probably because things have changed in more current versions of Android (2019 `:)` )) – Protomen Jun 13 '19 at 17:32
8
//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

Get-apk icon

Community
  • 1
  • 1
Dipak Sonnar
  • 193
  • 2
  • 7
6

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:

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.

Ridcully
  • 23,362
  • 7
  • 71
  • 86
  • Thanks for the reply but unfortunately the AndroidManisfest.xml file is compiled to a binary format. If someone can find a small utility that would decompile the AndroidManifest.xml this would be a good solution. – www.jensolsson.se Oct 01 '12 at 13:08
3

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.

preview-android-icon () { unzip -p $1 $(aapt d --values badging $1 | sed -n "/^application: /s/.*icon='\([^']*\).*/\1/p") > /tmp/$$.png && preview /tmp/$$.png; }

Use it like this:

preview-android-icon /path/to/your.apk
JohnnyLambada
  • 12,700
  • 11
  • 57
  • 61
2

Software

You can also try these GUI tools to easily extract Android app icon:

Description

Though the Apktool is used under the hood, the GUI front-end makes it very simple to extract or change APK icons.

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.

APK Icon Editor

  • Both tools help you to easily edit, replace or extract icons via user-friendly GUI.
  • Both tools are available for Windows, macOS and Linux.
  • Both tools are open-source (written in C++/Qt).

Disclaimer

I am the author of these tools.

kefir500
  • 4,184
  • 6
  • 42
  • 48
1

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

Joe
  • 11
  • 1
0

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.

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.

mah
  • 39,056
  • 9
  • 76
  • 93
  • Thanks for the reply. I have also been thinking in these terms and I have started the work to extract the manifest decompilation part from apktool. But it would be very nice to find some tools that would do this out of the box. I was hoping there is such a tool somewhere. – www.jensolsson.se Oct 01 '12 at 13:10