How do I get list of all application packages together with their activity label from adb shell? Sometimes I have a trouble matching application's package name in /data/data/ or /data/app/*.apk with the user-friendly activity label I see in GUI.

How do I list application packages together with their activities?

Expecting something like this:

$ adb shell list_apps
de.shandschuh.sparserss "Sparse rss"
org.vudroid "VuDroid"
jcpezzullo.statical "StatiCal"
tone.control "Tone Control"
...
Based on my answer on the question Andrew linked to, this is what should be in your list_apps script:

for app in $(ls /data/app/*.apk); do
    appname=$(aapt d badging $app | grep 'application: label' | sed -n \"s/.*label\='\([^']*\)'.*/\1/p\")
    pkgname=$(basename $app)
    echo ${pkgname} "${appname}"
done


Run this on your Android device.


Requirements: Either a CM based ROM with Kitkat or higher (which seems to ship with the aapt binary) – or a rooted device where you can install aapt onto yourself (find it here; tested with Android 4.1).
Known issues: app name most likely gets truncated when it contains a single quote (see sed expression). Not having such one installed here I could not test that.
Only lists user apps. Easy to fix by repeating the block for /system/app ;)