Uninstalling apps using Python scripts and ADB commands

Source: Internet
Author: User
Tags python script
Preface

This article implements a Python script that can be used to bulk unload the App on the emulator or physical machine and clear the LogCat cache.

Android friends, simulators or mobile phones often have a lot of debugging of the demo, for the mobile phone is OK, but for the simulator, it is possible to cause the debugging speed and startup Speed drop. And the App in the simulator one delete is also very troublesome. With the ADB command, we can do a lot of things, including the batch operation simulator or the APP on the phone. Of course, it includes the delete operation. With the Python script and the ADB shell command and the CMD window with AS, we can condense all this into a command line.

Core code

# Delete all the Appdef Delallapp (): print ' Start delete all your apps in your Phone or Simulator ' Os.popen (' adb wait-for-dev Ice '); Corename = raw_input ("Input your app package Corename:") oripackages = Os.popen (' adb shell pm list Packages {name} '. Format (Name=corename));  # list all PackageName-oripackage in oripackages:deletepackage = Oripackage.split (': ') [1] os.popen (' adb uninstall '  + deletepackage); Print Deletepackage + "is deleted" # removes all the specific Appdef listallpackage () that you specify for the package name: i = 0 os.popen (' adb wait-for-device '); Corename = raw_input ("Input your app package Corename:") oripackages = Os.popen (' adb shell pm list Packages {name} '. Format  (Name=corename)); For oripackage in oripackages:deletepackage = Oripackage.split (': ') [1] Print str (i) + ":" + deletepackage DELETELIST.A Ppend (deletepackage) i + = # delete specified appdef Deleteapp (number): Os.popen (' adb uninstall ' + deletelist[number]); print ' delete ' + Deletelist[number] + "Success" # clear LogCat Cache def clearlogcat (): print ' Start clEar Logcat Buffer in your Phone or Simulator ' Os.popen (' adb wait-for-device '); Os.popen (' adb logcat-c '); print ' Logcat is cleared success '

Effect implementation

How to use

    1. Make sure your as is able to use the ADB command

    2. Configure the Python 2.7 environment (there should be no problem with it)

    3. Locate the current script path input in the CMD provided by as: python unistall.py

    4. Follow the command prompt to enter the core keywords of the package you want to remove the App from, such as: com.example.RxCacheDemo , enter example (everyone as this configuration should be the same)

    5. After the above steps are completed, you will be prompted to delete the success or not.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.