delete packages of domain by adb shell pm

独自空忆成欢 提交于 2019-12-01 11:33:06

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.

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

for mac users:

adb shell pm list packages com.your.domain \
| cut -d ':' -f 2 \
| tr -d '\r' \
| xargs -L1 -t adb uninstall
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!