Use the Python script and ADB command to uninstall the App, pythonadb

Source: Internet
Author: User

Use the Python script and ADB command to uninstall the App, pythonadb

Preface

This article implements a Python script to uninstall the apps on the simulator or physical machine in batches and clear the LogCat cache.

Android Developers, simulators, or mobile phones often have a large number of debugging demos, which are good for mobile phones. However, simulators may cause a reduction in debugging speed and startup speed. In addition, it is difficult to delete apps one by one in the simulator. Using the ADB command, we can do a lot of things, including batch operation simulators or apps on mobile phones. Of course, this includes the delete operation. With the Python script, the ADB shell command, and the CMD window that comes with the AS, We can condense all of this into a command line.

Core code

# Delete all APPdef delAllapp (): print 'start delete all your app in your Phone or Simulator '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); # list all PackageName for oriPackage in oriPackages: deletePackage = oriPackage. split (':') [1] OS. popen ('adb uninstall' + deletePackage); print deletePackage + "is deleted" # delete all the specified APPdef listAllpackage (): 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. append (deletePackage) I + = 1 # Delete the specified Appdef deleteApp (number): OS. popen ('adb uninstall' + deleteList [number]); print 'delete' + deleteList [number] + "success" # Clear the 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

Usage

  1. Make sure your AS can use the ADB command
  2. Configure the Python 2.7 environment (3 + should be okay)
  3. Find the current script path input in the CMD provided by: python unistall.py
  4. Enter the core Keywords of the package you want to delete the App according to the command prompt, such:com.example.RxCacheDemo, Enter example (this configuration should be the same for everyone's)
  5. After the preceding steps are completed, a message indicating whether the deletion is successful or not is displayed.

Summary

The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.

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.