ADB Connection - Cloud Phone
1、Enable ADB for Cloud Phone
- Use MoreLogin API "Cloud Phone" - "update Cloud Phone ADB status" interface to enable ADB.After enabling ADB successfully, call the "Cloud Phone - Getting a list of cloud phone profiles" interface to get the "Connection Address" and "Connection Code".
- Sample code:
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、Connect and use ADB
- After enabling ADB, enter "ADB connect address" in the command prompt interface to connect to the target address. After successfully logging in with the connection code, you can start using ADB
- Sample code:
# -*- 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 commands
You can click the link below to view: