Skip to content

Instantly share code, notes, and snippets.

@davidnunez
Created November 29, 2011 13:20
Show Gist options
  • Save davidnunez/1404789 to your computer and use it in GitHub Desktop.
Save davidnunez/1404789 to your computer and use it in GitHub Desktop.
list all installed packages in android adb shell
pm list packages -f
@JohnLBevan
Copy link

Hey @AndroidDeveloperLB I'm afraid I don't know much about adb itself... Best to post questions somewhere like https://android.stackexchange.com/ to get help from the community at large.

@AndroidDeveloperLB
Copy link

@JohnLBevan OK thanks.

@DerGoogler
Copy link

Get every ID from app

for i in $(pm list packages -U | cut -f 3 -d ":"); do echo $(id -un $i); done;

@cpuuntery
Copy link

@AndroidDeveloperLB
You get apps name with the corresponding package name, you just need a Linux machine with aapt binary to get the app name

aapt download links
https://androidaapt.com/
https://aaptdownload.com/

And the links to the script that will get the app and package name
https://stackoverflow.com/a/73186928
https://stackoverflow.com/a/67654499

@AndroidDeveloperLB
Copy link

@cpuuntery Linux? Does it mean I can do it even on Android itself?

@cpuuntery
Copy link

@AndroidDeveloperLB

Yes, you can run it inside termux or adb shell,
but you need to find a version of aapt compiled for arm64
the appt in my link are compiled for x86

and if you managed to run appt on android
there is even a script in the case that you want to run aapt on android provided that you have arm64 aapt. and you can filter based on permission usage


#!/system/bin/sh

# List package name of all the installed apps and save them in the file packages.txt under /sdcard
pm list packages | sed 's/^package://g' | sort -o /sdcard/packages.txt

# For each package name in the output we just saved, get the app's label using $path and $label, print a line and then finally list the permissions granted to the app 
while read line; do 
    path=$(pm path $line | sed 's/^package://g'); 
    label=$($aapt d badging $path  | grep 'application: label=' | cut -d "'" -f2);  
     printf "Permissions for app $label having package name $line\n"; 
    dumpsys package $line | sed -e '1,/grantedPermissions:/d' -e '/^\s*$/,$d' | sort;
     printf "\n"; 
done < /sdcard/packages.txt

(you can remove the busybox part from the script above because they are not needed)

I found this repo that has aapt compiled for arm64

@cpuuntery
Copy link

@AndroidDeveloperLB
i was able to make the old script work.

The first thing you need to do is to get the aapt binary from this repo

note aapt2 is the newer version of appt, but it is slower in parsing the data from apk files only use aapt2 when you get errors with aapt

the repo will find android 9 and android 11 choose the closest one to the version of your android device
copy aapt to /data/local/tmp if you plan to use adb shell
or
copy appt to data/data/com.termux/files/home if you use termux
then
chmod -R 770 *
for termux you need to give it a special permission using adb
adb shell pm grant com.termux android.permission.DUMP

and lastly there will be three versions of the script
the first will be aapt list all apps names
the second appt list app based on permission usage
the third will be appt2 list all apps

Remember to change appt or appt2 to the path of your files (it is the second line in the script)

aapt list all apps names

#!/system/bin/sh
aapt=/data/local/tmp/aapt/aapt
pm list packages | sed 's/^package://g' | while read line; do 
    path=$(pm path $line | sed 's/^package://g'); 
    label=$($aapt d badging $path  | grep 'application: label=' | cut -d "'" -f2);  
    printf "app $label having package name $line\n"; 
    printf "\n"; 
done 

appt list app based on permission usage

#!/system/bin/sh
aapt=/data/local/tmp/aapt/aapt
pm list packages | sed 's/^package://g' | while read line; do [[ `dumpsys package $line | grep 'android.permission.INTERNET'` ]] && echo "$line"; done | while read line; do 
    path=$(pm path $line | sed 's/^package://g'); 
    label=$($aapt d badging $path  | grep 'application: label=' | cut -d "'" -f2);  
    printf "app $label having package name $line\n"; 
    printf "\n"; 
done  

appt2 list all apps

#!/system/bin/sh
aapt2=/data/local/tmp/aapt2/aapt2
pm list packages | sed 's/^package://g' | while read line; do 
    path=$(pm path $line | sed 's/^package://g'); 
    label=$($aapt2 dump $path | grep -A 1 string/app_name | grep -o -m 1 '".*"' | cut -d '"' -f2);  
    printf "app $label having package name $line\n"; 
    printf "\n"; 
done 

@SashaDesigN
Copy link

adb shell 'pm list packages' | sed 's/.*://g'

thx worked well

@theChandrayMurmu
Copy link

What is the command that shows the list of user-installed applications on the Android Phone?

@Anubioz
Copy link

Anubioz commented Oct 1, 2024

What is the command that shows the list of user-installed applications on the Android Phone?

pm list packages -3

(as in 3-rd party)

That fortunately requires root to work

@theChandrayMurmu
Copy link

(as in 3-rd party)

That fortunately requires root to work

@Anubioz Thank you for your reply. However, my phone is not rooted. I will look for an alternative solution and let you know if I find anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment