delete packages of domain by adb shell pm

后端 未结 3 1390
终归单人心
终归单人心 2021-01-06 13:32

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.         


        
相关标签:
3条回答
  • 2021-01-06 14:15

    for mac users:

    adb shell pm list packages com.your.domain \
    | cut -d ':' -f 2 \
    | tr -d '\r' \
    | xargs -L1 -t adb uninstall
    
    0 讨论(0)
  • 2021-01-06 14:22

    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
    
    0 讨论(0)
  • 2021-01-06 14:23

    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.

    0 讨论(0)
提交回复
热议问题