Nautilus - Thumbnailer for APK files



On Android devices, all programs are installed thru some APK archives. Under Gnome Nautilus, these APK archives are recognised as a specific mime types and are displayed with some generic text file icon.

As most of the time the name of these APK archives is not very friendly, it is difficult to associate an APK file with the Android application it contains. To help you with this association, it could be very helpful to display the application icon as it is done under Android instead of the generic icon.

Thanksfully, under Gnome Shell, Nautilus allows to generate a specific thumbnail according to the APK mime type application/ As APK archive are supposed to contain their Android application icon, it becomes possible to display the application icon as the Nautilus thumbnail. You can also add APK version provided by the embedded manifest.xml.


This article explains all the steps needed to configure Nautilus to display the APK embedded application icon as thumbnail. This allows you to handle your APK files from Nautilus as they appear on your Android device.

This procedure has been tested under Ubuntu Precise 12.04 LTS, Ubuntu Gnome 14.04 LTS and even LUbuntu 14.04 with PCManFM.
It should be applicable to many other distributions.

1. Install Unzip and Imagemagick

As the thumbnailer script uses gvfs-copy, unzip and convert, make sure both tools are installed on your system :

# sudo apt-get install gvfs-bin unzip imagemagick

Next we need to install aapt utility which is coming from Android SDK. If you don't want to install the full SDK, you can only install the tool itself. Just download the tool according to your architecture :

Once you've downloaded the correct package, just install it :

# sudo dpkg -i android-tools-aapt_*.deb

2. Create the Thumbnailer

When Nautilus needs to generate a thumbnail for a file, it is calling a 'thumbnailer'. This program (or script) is in charge of generating the thumbnail in a PNG format with a given height.

When we deal with APK archives, the thumbnail can be generated from the embedded icons. In fact every APK archive is a standard ZIP archive and is most of the time embedding some icons that will be used to display the application icon on the android desktop.

Icons may be available in different formats in the package (ldpi, mdpi, hdpi, xhdpi), but most of the time official package icon is having a mdpi or hdpi resolution.

You can use the aapt tool available from android SDK to determine the application icon. Icon files are listed with the d badging option.

# aapt d badging com.whatsapp.apk | grep application | grep icon
application: label='WhatsApp' icon='res/drawable-hdpi/icon.png'

The following script is a Nautilus 'thumbnailer' that will do the thumbnailing job using aapt :


# ---------------------------------------------------
# Thumbnailer for APK archives files
# Display embedded icon and version number (option)
# Procedure :
# Depends on :
#   * unzip
#   * convert (imagemagick package)
#   * aapt
#   * gvfs
# Parameters :
#   $1 - URI of APK archive
#   $2 - full path of generated thumbnail
#   $3 - height of thumbnail in pixels
# Revision history :
#   04/08/2013, V1.0 - Creation by N. Bernaerts
#   11/08/2013, V1.1 - Use aapt to get icon file
#   05/11/2014, V2.0 - Add version display
#   06/11/2014, V2.1 - Don't use renamed aapt anymore
#   15/11/2014, V3.0 - Use URI to handle network shares
# ---------------------------------------------------

# check tools availability 
command -v gvfs-copy >/dev/null 2>&1 || exit 1
command -v aapt >/dev/null 2>&1 || exit 1
command -v unzip >/dev/null 2>&1 || exit 1
command -v convert >/dev/null 2>&1 || exit 1

# select to display version on the icon
# set to yes to display version number on the icon

# get parameters

# get filename extension
FILE_EXT=$(echo "$FILE_URI" | sed 's/^.*\.\(.*\)/\1/')

# generate temporary local filename

# copy input file to temporary local file
gvfs-copy "${FILE_URI}" "${TMP_FILE}"

# get application icon
ICON=$(aapt d badging "${TMP_FILE}" | grep "application-icon" | sed 's/^.*icon-\(.*\):.\(.*\).$/\2/' | tail -1)

# if icon exists, extract icon & generate thumbnail 
if [ "$ICON" != "" ] ;
  # if needed, add version display options
  if [ "$DISPLAY_VERSION" = "yes" ] ;
    # get version
    VERSION=$(aapt d badging "${TMP_FILE}" | grep versionName | sed 's/^.*versionName=.\(.*\)..*$/\1/')

    # calculate optimum font size
    FONT_SIZE=`echo $HEIGHT / 5 | bc`

    # generate icon including version number
    unzip -p "${TMP_FILE}" "${ICON}" | convert -resize x${HEIGHT} - -pointsize $FONT_SIZE -fill black -gravity south -undercolor white -annotate 0 " $VERSION " "${FILE_THUMB}"

  # else, generate plain icon without version number
    unzip -p "${TMP_FILE}" "${ICON}" | convert -resize x${HEIGHT} - "${FILE_THUMB}"

# remove temporary local file
rm ${TMP_FILE}

You can install this thumbnailer with the following commands :

# sudo wget -O /usr/local/sbin/apk-thumbnailer
# sudo chmod +rx /usr/local/sbin/apk-thumbnailer

If you want the thumbnailer to display version number on the icon, you need to edit the script and set DISPLAY_VERSION="yes"

3. Declare the Thumbnailer

To allow Nautilus to use the proper thumbnailer for APK archives, you need to declare the previous script as the thumbnailer for the mime type of APK archives (application/

This declaration is done via a apk.thumbnailer file placed under /usr/share/thumbnailers. This file follows a specific format, where association between the mime type and the thumbnailer is done.

A complete description of this file format is available from Gnome Developers site on the page Installing a Thumbnailer Program.

As we want to get APK icon even for file which are accessed thru a network share, we will use the file URI instead of it's plain filename. This will allow the thumbnailer script to handle the files thru GVFS.


[Thumbnailer Entry]
Exec=/usr/local/sbin/apk-thumbnailer %u %o %s

You can download this thumbnailer declaration file with the following commands :

# sudo wget -O /usr/share/thumbnailers/apk.thumbnailer

4. Enjoy your APK Thumbnails

You can now purge your thumbnails to allow them to re-generate and restart nautilus to reload the thumbnailer scripts.

# rm -r $HOME/.cache/thumbnails
# nautilus -q

Please note that if you run Lubuntu, thumbnails should be removed under $HOME/.thumbnails and thumbnailer will work after next reboot.

You will now enjoy to see your APK archives displayed with their embedded icons.

Hope it helps,

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus