delete packages of domain by adb shell pm

丶灬走出姿态 提交于 2019-12-30 11:16:06

问题


There is a command to ease the pain of managing packages for Android phone,

adb shell pm uninstall org.kde.necessitas.example.one
adb shell pm uninstall org.kde.necessitas.example.two

But I have many phones and just want to delete all packages from a particular domain on them.

It cannot be done by

adb shell pm uninstall org.kde.necessitas.example.*

what is your suggestion?


回答1:


You can use the following in a batch file: (I am assuming Windows though)

  adb shell pm list packages org.kde.necessitas.example > packages.txt

  for /F "tokens=2 delims=:" %%a in (packages.txt) do adb shell pm uninstall %%a

You could take it a step further and make the search text a parameter:

  adb shell pm list packages %1 > packages.txt

  for /F "tokens=2 delims=:" %%a in (packages.txt) do adb shell pm uninstall %%a

This pipes the output of the pm list packages command into a text file and then loops through each line of the text file. It calls adb shell pm uninstall for each second token in the line which in this case is the package name.




回答2:


If you're sat in a shell on the phone itself, you can do this (all on one line, if you want):

for i in $(pm list packages com.your.domain ) ; do
    pm uninstall ${i#*:} ;
done

If you're on the host machine and you're using something Unixy - Linux, Mac, Cygwin - then something similar will work there too, but you need to shove 'adb shell' in:

for i in $(adb shell pm list packages com.your.domain ) ; do
    adb uninstall ${i#*:} ;
done

Since you're talking about removing the packages from all connected phones, you need yet another loop:

for d in $(adb devices | sed '/List/d; /\*/d; s/device$//') ; do
    for i in $(adb -s $d shell pm list packages com.your.domain ) ; do
        adb -s $d uninstall ${i#*:} ;
    done
done



回答3:


for mac users:

adb shell pm list packages com.your.domain \
| cut -d ':' -f 2 \
| tr -d '\r' \
| xargs -L1 -t adb uninstall


来源:https://stackoverflow.com/questions/15458909/delete-packages-of-domain-by-adb-shell-pm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!