首页 > 技术文章 > python借助ADB工具实现自动化操作手机

zhuminghui 2019-02-28 13:51 原文

核心工具——ADB工具

  adb工具用于连接Android手机和PC端,我们借助adb工具,就可以通过命令行对手机进行相应的操作

  注意:若要通过adb操作手机,需打开手机的开发者模式,并打开USB调试功能

adb下载链接:https://developer.android.com/studio/releases/platform-tools?hl=en

 

根据操作系统下载相应的工具包就行,下载完成后会得到一个platform-tools文件夹,adb就在里面,将命令终端cd到该文件夹下即可使用adb命令。windows系统需要将adb所在路径添加到环境变量中

 

简单操作命令

adb shell input keyevent 26  # 电源键
adb shell input keyevent 3   # home键
adb shell input keyevent 4   # 返回键
adb shell input tap x y      # 触击屏幕第x行,第y列的点
adb shell getprop ro.product.model # 获取手机型号
adb shell wm size            # 获取屏幕分辨率

 

adb工具的命令有着一套完整的格式,具体adb命令大全参考链接:

 

python操作

  python中的os库可以执行系统命令,即利用python脚本实现执行系统命令的功能,这样就可以在python的程序中随时调用adb程序

基本写法

os.system(adb命令)

 

      

 

 

 

推荐阅读