2

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"
...
1

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 ;)
  • On Samsung Galaxy S 5, ls /data yields opendir failed, Permission denied. – Stéphane Gourichon Aug 25 '17 at 11:41
  • 1
    @StéphaneGourichon requirements not met, see first bullet-point: you need to be root for that. – Izzy Aug 27 '17 at 15:44
  • fully valid point yet unexpected. Firelord's comment mentions non-root but mentions entering /data also. Yet I remember having used an app that did this without root access. My guess is, there is probably a way to fulfill OP's question on a non-rooted device, perhaps just aapt in another temp location. – Stéphane Gourichon Aug 28 '17 at 3:29
  • @StéphaneGourichon you've missed one thing possibly: ls /data requires root, ls /data/app might not. I'm not sure about the permissions on that folder, but I wouldn't wonder if it's readable and executable to each app. Have you checked that? While without root you cannot list the contents of /data, you can cd into it, and also into /data/app. You just cannot list the contents of /data itself. But without access to tha .apk file it doesn't help to place aapt in another location either; the information required is stored in the .apk files. – Izzy Aug 28 '17 at 5:37
  • thanks. Yes and no. You're right in that I can cd into /data and /data/app. But ls still fails in both locations, making the whole operation impractical. I expect the app did it via some API which has necessary access. – Stéphane Gourichon Aug 28 '17 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.