adb的全称为Android Debug Bridge,就是起到调试桥的作用。借助adb工具,我们可以管理设备或手机模拟器的状态。还可以进行很多手机操作,如安装软件、系统升级、运行shell命令等等。其实简而言说,adb就是连接Android手机与PC端的桥梁,可以让用户在电脑上对手机进行全面的操作。
常用adb指令:
import os
# os.system("adb connect 127.0.0.1:7555") # 使用TCP/IP连接设备 例如网易MM模拟器
# os.system("adb devices") # 查看已连接色设备
# os.system("adb shell input tap 200 50") # 点击屏幕X200,Y50处
# os.system("adb shell input swipe 55 212 630 217.6 100000") # 将X55,Y212拖到X630,Y217.6处,耗时100000
# os.system("adb shell input swipe 55 212 630 217.6) # 将X55,Y212拖到X630,Y217.6处
# os.system("adb shell input keyevent 3") # HOME键
# os.system("adb shell input keyevent 4") # 返回已键
# os.system("adb shell input keyevent 24") # 音量+
# os.system("adb shell input keyevent 25") # 音量—
# os.system("adb shell input keyevent 26") # 打开/关闭屏幕
# os.system("adb shell ps") # 查看进程
# os.system("adb shell ps|grep xxxx") # 查看xxxx的进程
# os.system("adb shell kill 5450") # 结束PID为5440的进程
# os.system("adb start 5450") # 启动PID为5450的进程
# os.system('adb shell dumpsys window windows | findstr "Current"') # 获取当前打开的应用程序的package和launch activity
# os.system("adb shell am start -n xxxx/xxxx") # 启动xxxx应用的xxxxx activity
# os.system("adb shell am broadcast -a clipper.get") # 获取粘贴板的内容 需要安装一个软件https://github.com/majido/clipper
# os.system('adb shell am broadcast -a clipper.set -e text "this can be pasted now"') # 设置粘贴板的内容