ADB连接-云手机
1、开启云手机ADB
- 使用 MoreLogin API 「云手机」-「更新云手机ADB状态」接口开启ADB。开启ADB成功后,调用「云手机-获取云手机环境列表」接口,能够得到“连接地址”和“连接码”
- 示例代码:
def updateAdb():
requestPath = '/api/cloudphone/updateAdb'
data = {'ids': [156**********795], "enableAdb": 'true'}
headers = requestHeader()
headers['Content-Type'] ='application/json'
response = requests.post(BASEURL + requestPath, json=data, headers=headers)
print(response.content)
2、连接并使用ADB
- 开启ADB后,在命令提示符界面输入“adb connect 连接地址”以连接目标地址,使用连接码登录成功后可开始使用ADB
- 示例代码:
# -*- coding: utf-8 -*-
import os
import time
import datetime
import requests
import json
def click(device, x, y):
os.system("adb -s {} shell input tap {} {}".format(device, int(x), int(y)))
def swipe(device, start_x, start_y, end_x, end_y, duration=100):
os.system("adb -s {} shell input swipe {} {} {} {} {}".format(device, int(start_x), int(start_y), int(end_x), int(end_y), duration))
def launche_app(device, activity):
os.system("adb -s {} shell am start -n {}".format(device, activity))
def input_text(device, text):
os.system(r'adb -s {} shell "input text \"{}\""'.format(device, text))
def input_keyevent(device, keycode):
os.system('adb -s {} shell input keyevent {}'.format(device, int(keycode)))
def screenShootAndSave(device, localfilepath):
now = datetime.datetime.now()
file_name = "screecap_{}.png".format(now.strftime('%Y%m%d_%H%M%S'))
os.system("adb -s {} shell screencap -p /sdcard/{}".format(device, file_name))
time.sleep(1)
os.system("adb -s {} pull /sdcard/{} {}\{}".format(device, file_name, localfilepath, file_name))
time.sleep(1)
os.system('adb -s {} shell rm /sdcard/{}'.format(device, file_name))
3、ADB命令大全
可点击下方链接查看: