Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use adb to uninstall all 3rd party user apps?

Tags:

android

adb

xargs

I am trying to create a script that will retrieve and uninstall all user apps in one batch operation through adb. Does anyone know how I would be able to do this?

I can currently list out all 3rd party apps through

adb shell pm list packages -3

Could I somehow direct the list of packages this generates into an uninstall command in adb?

like image 388
Troy Greenman Avatar asked Aug 14 '13 23:08

Troy Greenman


People also ask

How do you uninstall third party applications?

Go to the Security section of your Google Account. Under “Third-party apps with account access,” select Manage third-party access. Select the app or service you want to remove. Select Remove Access.


2 Answers

Try:

adb shell pm list packages -3 | cut -d':' -f2 | tr '\r' ' ' | xargs -r -n1 -t adb uninstall
  • First part is to get 3rd party app package names
  • second part is to split package names using delimiter :
  • third part is to replace carriage return with space (sometimes it would be a problem in linux machines. Try removing this part and check if you face it)
  • and the last one is for uninstalling one by one
    • r option will prevent xargs from running the command if there are no third party apps installed
    • n1 option is to pass one result value as argument at a time to the command
    • t is for printing the command being executed)

Hope it helps!!!

like image 141
Ramraj Avatar answered Oct 29 '22 00:10

Ramraj


What seems to be the problem? It can be done with this one-liner:

adb shell "pm list packages -3 | cut -c9- | xargs pm uninstall"
like image 26
Alex P. Avatar answered Oct 29 '22 02:10

Alex P.