In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how python uses computers to operate Android phones". The editor shows you the operation process through practical cases. The operation method is simple, fast and practical. I hope this article "how python uses computers to operate Android phones" can help you solve the problem.
Download and install SDK Platform Tools on your computer
Downloaded file: platform-tools_r30.0.4-windows.zip (about 12m)
Then extract the file to the specified directory
Extract the paths and files, and then add system environment variables to the tool catalog
Verify the installation result
# execute the command adb version
After connecting the phone to the computer USB, execute adb devices to check the connection status of the phone.
Query connected devices / simulator: adb devices
To connect to the phone here, you need to enable the USB debugging feature in developer mode. By the way, it also turns on the analog button function, which will be used later.
The following problems often occur with this command:
Offline-indicates that the device is not connected or unresponsive
Device-the device is connected
No device-no device / simulator connection
The List of devices attached device / simulator is not connected to the adb or is not responding
A simple method to obtain the coordinates of mobile phone screen
Method 1. Enter the developer mode of the phone, turn on the function of displaying coordinates in real time on the phone, and automatically display the coordinates by pressing the screen position for a long time.
Method 2. Use the android adb shell command to get
# Screenshot to the phone adb shell screencap / sdcard/screen.png# and upload the screenshot from the phone to the computer adb pull / sdcard/screen.png / Users/Administrator/Desktop/screen.png
From the original picture, use PS to deduct the local picture you want, and then use the following code to get the coordinates of the local picture on the original picture.
Do not use PS, you can directly use screenshots to take screenshots on the original image, but not as fine as PS.
Import aircv as ac# looks up the coordinates on the picture according to the picture # imgsrc= original image For the picture to be found by imgobj=, confidence= sets the matching coefficient def matchImg (imgsrc, imgobj, confidence=0.2): imsrc = ac.imread (imgsrc) imobj = ac.imread (imgobj) match_result = ac.find_all_template (imsrc, imobj, confidence) return match_resultif _ _ name__ ='_ _ main__': p = matchImg ("C:\ Users\ Administrator\ Desktop\ screen.png" "C:\ Users\ Administrator\ Desktop\ daicha.png") print (p) controls the phone import osimport timedef execute (cmd) using python: adbstr = 'adb shell {}' .format (cmd) print (adbstr) os.system (adbstr) if _ name__ = ='_ main__': while True: # Click location-execute ("input tap 350 2200") time.sleep (3) # Click location 2 execute ("input tap 970135") time.sleep (5) android adb shell common commands
Official order of android adb Shell https://adbshell.com/
The following command sources:
1. Simulated click
Adb shell input tap 100 100
two。 Slide
Adb shell input swipe x1 y1 x2 adb input touchscreen swipe x1 y1 x2 y2 100adb shell input swipe 100 100 400 100 300 # left to right adb shell input swipe 400 100 100 100 300 # right to left adb shell input swipe 100 100 100 300 # up and down adb shell input swipe 100 400 100 100 300 # downward slope adb shell input swipe 400 400 100 100 300 # up slope adb shell input swipe 400 400 100 100 300 #
3. Long press
Adb shell input swipe 100100100100100 1000 / / 1000 milliseconds at 100100 position adb shell input swipe 367,469,367,469,800
4. Print all package names
Adb shell pm list packages ➜~ adb shell pm list packagespackage:com.huawei.floatMmspackage:com.android.defcontainerpackage:com.tencent.mm
5. Print the apk path of the set package
Adb shell pm path com.android.phone ➜~ adb shell pm path com.huawei.android.launcherpackage:/system/app/HwLauncher6.apk
6. Delete a defined package
Adb shell pm clear com.test.abc
7. Screenshot
Adb shell screencap / sdcard/screen.pngadb pull / sdcard/screen.png # download to local
8. Get the location information that was clicked
Adb shell getevent > / dev/input/event0 3 39 3e1/dev/input/event0 1 14a 1/dev/input/event0 1 145 1/dev/input/event0 3 35 406 / / x coordinates / dev/input/event0 3 54 1083 / / y coordinates / dev/input/event0 0 0/dev/input/event0 3 39 ffffffff/dev/input/event0 1 14a 0/dev/input/event0 1 145 0/dev/input/event0 0 0getevent-l-c 16 outputs the basic message of all event devices Add device 1: / dev/input/event2 name: "hi6421_on" could not get driver version for / dev/input/mouse0 Not a typewriteradd device 2: / dev/input/event4 name: "huawei,touchscreen" add device 3: / dev/input/event0 name: "mhl_rcp_dev" could not get driver version for / dev/input/mice Not a typewriteradd device 4: / dev/input/event1 name: "hisi_gpio_key.14" add device 5: / dev/input/event3 name: "hi3630_hi6401_CARD Headset Jack" getevent-c 10 / / exit getevent-l / / display type, code, value with corresponding constant names
9. Open the corresponding activity
Adb shell am start-n {package (package) name} / {package name}. {activity (activity) name} adb shell am start com.songheng.eastnews/com.oa.eastfirst.activity.WelcomeActivity
10. Get the information, package name and active form of the current active window
Adb shell dumpsys window windows | grep mCurrent
11. Package name management command to get the corresponding apk path of the corresponding package name
Adb shell pm path com.migu.lobby
twelve。 Use the dumpsys command to view the Activity currently running on an Android phone.
Adb shell dumpsys activity activities | findstr "Run"
13. Use uiautomator dump to get page elements on app
Adb shell uiautomator dump / data/local/tmp/uidump.xmladb shell uiautomator dump / sdcard/dump.xml
14. Download a file
Adb pull / sdcard/demo.mp4
15. Upload files
Adb push test.apk / sdcard
16. Information screen
Adb shell input keyevent 26
17.keyevent
Adb shell input keyevent 20 # Down adb shell input keyevent 4 # return adb shell input keyevent 3 # Homeadb shell input keyevent 6 # Hang up adb shell input keyevent 84 # search adb shell input keyevent 26 # Power adb shell input keyevent 24 # Volume + adb shell input keyevent 25 # Volume-
18. Input box input
Adb shell input text "ANDROID"
19. Use wireless to view adb shell
> adb tcpip 5555 connection: > adb connect IP:5555
20. View all connected devices
Adb devices
21. Install and uninstall
Adb install adb install-r installs the apk file through the install command, and the-r parameter reinstalls an application and retains the application data adb install-r ~ / chrome.apk uninstall the application: adb uninstall adb uninstall-k
< 软件名>If you add the-k parameter, to uninstall the software but keep the configuration and cache file adb uninstall com.android.chrome
twenty-two。 Shutdown command
This is the end of adb shellsureboot-p's introduction to "how python uses computers to operate Android phones". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.