AndroidInstance

AndroidInstance

TCGSDK - AndroidInstance 子模块相关方法

需要正常 CloudGamingWebSDK TCGSDK.init 后,再调用 AndroidInstance 相关方法

AndroidInstance 是 TCGSDK 的子模块,用于操作 Android 设备,包括的几类操作能力如下:

  1. 连接单个实例看到云手机画面,以及云手机各种操作
  2. 通过截图预览多个云手机的画面
  3. 其他各类功能操作

android_instance

Example

const AndroidInstance = TCGSDK.AndroidInstance()

Methods

setMaster(params) → {void}

设置 master

Example
AndroidInstance.setMaster({instanceId: 'cai-xxx1'});
Parameters:
Name Type Description
params Object
Properties
Name Type Description
instanceId string

master的 instanceId

Returns:
Type
void

startSync(params) → {void}

Default Value:
  • 全量同步

开始同步,根据设置的 instanceIds 进行同步

Example
AndroidInstance.startSync({instanceIds: ['cai-xxx1', 'cai-xxx2']});
Parameters:
Name Type Description
params Object
Properties
Name Type Description
instanceIds Array

string[] 需要同步的设备列表

Returns:
Type
void

stopSync() → {void}

停止同步(全量)

Example
AndroidInstance.stopSync();
Returns:
Type
void

requestStream(param) → {void}

请求被控串流

Example
TCGSDK.requestStream({instanceId: 'cai-xxxx-xxxx', status: 'open', level: 'normal'});
Parameters:
Name Type Description
param Object
Properties
Name Type Description
instanceId string

请求串流的 instanceId

status 'open' | 'close'

串流状态

Returns:
Type
void

setSyncList(param) → {void}

设置同步列表

Example
TCGSDK.setSyncList({list: ['cai-xxxx-xxx1', 'cai-xxxx-xxx2']});
Parameters:
Name Type Description
param Object
Properties
Name Type Description
list Array.<string>

需要同步的 instanceId 列表

Returns:
Type
void

joinGroupControl(params) → {void}

中途加入群控

Example
AndroidInstance.joinGroupControl({instanceIds: ['cai-xxx1', 'cai-xxx2']});
Parameters:
Name Type Description
params Object
Properties
Name Type Attributes Description
instanceIds Array.<string>

需要加入的实例列表

clientSessions Array.<string> <optional>

clientSession

Returns:
Type
void

leaveGroupControl(params) → {void}

中途离开群控

Example
AndroidInstance.leaveInstances({instanceIds: ['cai-xxx1', 'cai-xxx2']});
Parameters:
Name Type Description
params Object
Properties
Name Type Description
instanceIds Array.<string>
Returns:
Type
void

setImageEvent(params) → {void}

设置截图事件

Example
AndroidInstance.setImageEvent({interval: 10, quality: 50});
Parameters:
Name Type Description
params Object
Properties
Name Type Attributes Description
interval number

截图事件的间隔,单位毫秒

quality number <optional>

截图质量,取值范围 0-100

Returns:
Type
void

getInstanceImage(params) → {Object|object}

Properties:
Name Type Description
url string

获取实例截图信息

Example
AndroidInstance.getInstanceImage({instanceId: 'cai-xxx1'});
Parameters:
Name Type Description
params Object
Properties
Name Type Attributes Description
instanceId string

实例 Id

quality number <optional>

截图质量,取值范围 0-100,默认 20

Returns:
  • response url - 截图地址

    Type
    Object
  • Type
    object

transMessage(params) → {void}

发送 App binder 消息

单连接适用

Example
AndroidInstance.transMessage({packageName: 'com.example.myapplication', message: 'abc123'});
Parameters:
Name Type Description
params Object
param.packageName string

PackageName

param.message string

消息

Returns:
Type
void

setLocation(params) → {Promise.<BatchTaskResponse>}

设置设备 GPS 信息

Example
AndroidInstance.setLocation({'cai-xxx1': {Longitude: 113.32412, Latitude: 23.124124}, 'cai-xxx2': {Longitude: 114.32412, Latitude: 24.124124}})
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object
Properties
Name Type Description
Longitude number
Latitude number
Returns:
Type
Promise.<BatchTaskResponse>

setResolution(params) → {Promise.<BatchTaskResponse>}

设置设备 Resolution

Example
AndroidInstance.setResolution({'cai-xxx1': {Width: 720, Height: 1080}, {'cai-xxx2': {Width: 720, Height: 1080}})
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object
Properties
Name Type Description
Width number
Height number
DPI number
Returns:
Type
Promise.<BatchTaskResponse>

paste(params) → {Promise.<BatchTaskResponse>}

往设备粘贴文本

Example
AndroidInstance.paste({'cai-xxx1': {Text: 'abc'}, {'cai-xxx2': {Text: '123'}})
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object
Properties
Name Type Description
Text string

要粘贴的文本

Returns:
Type
Promise.<BatchTaskResponse>

sendClipboard(params) → {Promise.<BatchTaskResponse>}

发送文本到剪切板

Example
AndroidInstance.sendClipboard({'cai-xxx1': {Text: 'abc'}, {'cai-xxx2': {Text: '123'}})
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object
Properties
Name Type Description
Text string

要发送的内容

Returns:
Type
Promise.<BatchTaskResponse>

shake(params) → {Promise.<BatchTaskResponse>}

摇一摇

Example
AndroidInstance.shake({'cai-xxx1': {}, {'cai-xxx2': {}})
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value 暂时传空对象 {}

Returns:
Type
Promise.<BatchTaskResponse>

setSensor(params) → {Promise.<BatchTaskResponse>}

设置设备传感器信息

Example
AndroidInstance.setSensor({'cai-xxx1': {Type: 'accelerometer', Values: [10, 10, 10]},  {'cai-xxx2': {Type: 'gyroscope', Values: [10, 10, 10]}})
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object
Properties
Name Type Description
Type 'accelerometer' | 'gyroscope'

传感器leasing accelerometer(加速器),gyroscope(陀螺仪)

Values Array.<string>

传感器对应的值,数组长度为 3,分辨表示 x/y/z 轴的值

Returns:
Type
Promise.<BatchTaskResponse>

sendTransMessage(params) → {Promise.<BatchTaskResponse>}

发送 App binder 消息

Example
AndroidInstance.sendTransMessage({'cai-xxx1': {PackageName: 'com.example.myapplication', Msg: 'abc123'}})
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value 暂时传空对象 {}

Properties
Name Type Description
PackageName string

PackageName

Msg string

消息

Returns:
Type
Promise.<BatchTaskResponse>

describeInstanceProperties(params) → {Promise.<DescribeInstancePropertiesResponse>}

批量查询实例属性接口

Example
AndroidInstance.describeInstanceProperties({'cai-xxx1': {}, {'cai-xxx2': {}})
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value 暂时传空对象 {}

Returns:
Type
Promise.<DescribeInstancePropertiesResponse>

listUserApps(params) → {Promise.<ListUserAppsResponse>}

已安装第三方应用功能

Example
AndroidInstance.listUserApps({'cai-xxx1': {}, {'cai-xxx2': {}})
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value 暂时传空对象 {}

Returns:
Type
Promise.<ListUserAppsResponse>

modifyInstanceProperties(params) → {Promise.<BatchTaskResponse>}

修改实例属性

Example
AndroidInstance.ModifyInstanceProperties({'cai-xxx1': {
 DeviceInfo: {
       Brand: 'Samsung',
       Model: 'Galaxy S24',
     },
   ProxyInfo: {
     Enabled: true,
     Protocol: 'socks5',
     Host: 'proxy.example.com',
     Port: 1080,
     User: 'user123',
     Password: 'pass123',
   },
   GPSInfo: {
     Longitude: 121.4737,
     Latitude: 31.2304,
   },
   SIMInfo: {
     State: 1,
     PhoneNumber: '+8613812345678',
     IMSI: '460001234567890',
     ICCID: '89860123456789012345',
   },
   LocaleInfo: {
     Timezone: 'Asia/Shanghai',
   },
   LanguageInfo: {
    Language: 'zh',
    Country: 'CN',
  },
  ExtraProperties: [
    {
      Key: 'custom_property1',
      Value: 'value1',
    },
    {
      Key: 'custom_property2',
      Value: 'value2',
    },
  ]
}})
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Attributes Description
DeviceInfo Object <optional>

DeviceInfo

Properties
Name Type Attributes Description
Brand string <optional>

DeviceInfo - Brand

Model string <optional>

DeviceInfo - Model

ProxyInfo Object <optional>

ProxyInfo

Properties
Name Type Attributes Description
Enabled boolean <optional>

ProxyInfo - Enabled

Protocol string <optional>

ProxyInfo - Protocol

Host string <optional>

ProxyInfo - Host

Port number <optional>

ProxyInfo - Port

User string <optional>

ProxyInfo - User

Password string <optional>

ProxyInfo - Password

GPSInfo Object <optional>

GPSInfo

Properties
Name Type Attributes Description
Longitude number <optional>

GPSInfo - Longitude

Latitude number <optional>

GPSInfo - Latitude

SIMInfo Object <optional>

SIMInfo

Properties
Name Type Attributes Description
State number <optional>

SIMInfo - State

PhoneNumber string <optional>

SIMInfo - PhoneNumber

IMSI string <optional>

SIMInfo - IMSI

ICCID string <optional>

SIMInfo - ICCID

LocaleInfo Object <optional>

LocaleInfo

Properties
Name Type Attributes Description
Timezone string <optional>

LocaleInfo - Timezone

LanguageInfo Object <optional>

LanguageInfo

Properties
Name Type Attributes Description
Language string <optional>

LanguageInfo - Language

Country string <optional>

LanguageInfo - Country

ExtraProperties Array.<Object> <optional>

ExtraProperties

Properties
Name Type Attributes Description
Key string <optional>

ExtraProperties - Key

Value string <optional>

ExtraProperties - Value

Returns:
Type
Promise.<BatchTaskResponse>

modifyKeepFrontAppStatus(params) → {Promise.<BatchTaskResponse>}

修改前台应用保活状态

Example
AndroidInstance.modifyKeepFrontAppStatus({'cai-xxx1': {"PackageName": "com.example.app", "Enable": true, "RestartInterValSeconds": 5}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
PackageName string

PackageName

Enable boolean

Enable

RestartInterValSeconds number

重新拉起最长间隔

Returns:
Type
Promise.<BatchTaskResponse>

describeKeepFrontAppStatus(params) → {Promise.<BatchTaskResponse>}

查询前台应用保活状态

Example
AndroidInstance.describeKeepFrontAppStatus({'cai-xxx1': {}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Returns:
Type
Promise.<BatchTaskResponse>

unInstallByPackageName(params) → {Promise.<BatchTaskResponse>}

卸载应用

Example
AndroidInstance.unInstallByPackageName({'cai-xxx1': {"PackageName": "com.unwanted.app"}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
PackageName string

PackageName

Returns:
Type
Promise.<BatchTaskResponse>

startApp(params) → {Promise.<BatchTaskResponse>}

启动应用

Example
AndroidInstance.startApp({'cai-xxx1': {"PackageName": "com.launch.app", "ActivityName": "MainActivity"}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
PackageName string

PackageName

ActivityName string

ActivityName

Returns:
Type
Promise.<BatchTaskResponse>

stopApp(params) → {Promise.<BatchTaskResponse>}

停止应用

Example
AndroidInstance.stopApp({'cai-xxx1': {"PackageName": "com.running.app"}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
PackageName string

PackageName

Returns:
Type
Promise.<BatchTaskResponse>

clearAppData(params) → {Promise.<BatchTaskResponse>}

清除应用数据

Example
AndroidInstance.clearAppData({'cai-xxx1': {"PackageName": "com.data.app"}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
PackageName string

PackageName

Returns:
Type
Promise.<BatchTaskResponse>

enableApp(params) → {Promise.<BatchTaskResponse>}

启用应用

Example
AndroidInstance.enableApp({'cai-xxx1': {"PackageName": "com.disabled.app"}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
PackageName string

PackageName

Returns:
Type
Promise.<BatchTaskResponse>

disableApp(params) → {Promise.<BatchTaskResponse>}

禁用应用

Example
AndroidInstance.disableApp({'cai-xxx1': {"PackageName": "com.disabled.app"}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
PackageName string

PackageName

Returns:
Type
Promise.<BatchTaskResponse>

startCameraMediaPlay(params) → {Promise.<BatchTaskResponse>}

摄像头播放媒体文件

Example
AndroidInstance.startCameraMediaPlay({'cai-xxx1': {"FilePath": "/sdcard/video.mp4", "Loops": 3}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
FilePath string

FilePath

Loops string

循环次数,负数表示无限循环

Returns:
Type
Promise.<BatchTaskResponse>

stopCameraMediaPlay(params) → {Promise.<BatchTaskResponse>}

摄像头停止播放媒体文件

Example
AndroidInstance.stopCameraMediaPlay({'cai-xxx1': {}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Returns:
Type
Promise.<BatchTaskResponse>

describeCameraMediaPlayStatus(params) → {Promise.<DescribeCameraMediaPlayStatusResponse>}

查询当前摄像头媒体播放状态

Example
AndroidInstance.describeCameraMediaPlayStatus({'cai-xxx1': {}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Returns:
Type
Promise.<DescribeCameraMediaPlayStatusResponse>

displayCameraImage(params) → {Promise.<BatchTaskResponse>}

摄像头显示图片

Example
AndroidInstance.displayCameraImage({'cai-xxx1': {"FilePath": "/sdcard/image.jpg"}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
FilePath string

FilePath

Returns:
Type
Promise.<BatchTaskResponse>

addKeepAliveList(params) → {Promise.<BatchTaskResponse>}

增加后台应用保活应用

Example
AndroidInstance.addKeepAliveList({'cai-xxx1': {"AppList": ["com.wechat", "com.alipay", "com.dingtalk"]}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
AppList Array.<string>

AppList

Returns:
Type
Promise.<BatchTaskResponse>

removeKeepAliveList(params) → {Promise.<BatchTaskResponse>}

移除后台应用保活应用

Example
AndroidInstance.removeKeepAliveList({'cai-xxx1': {"AppList": ["com.wechat", "com.alipay", "com.dingtalk"]}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
AppList Array.<string>

AppList

Returns:
Type
Promise.<BatchTaskResponse>

setKeepAliveList(params) → {Promise.<BatchTaskResponse>}

覆盖设置后台应用保活应用

Example
AndroidInstance.setKeepAliveList({'cai-xxx1': {"AppList": ["com.wechat", "com.alipay", "com.dingtalk"]}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
AppList Array.<string>

AppList

Returns:
Type
Promise.<BatchTaskResponse>

describeKeepAliveList(params) → {Promise.<DescribeKeepAliveListResponse>}

查询当前后台应用保活列表

Example
AndroidInstance.describeKeepAliveList({'cai-xxx1': {}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Returns:
Type
Promise.<DescribeKeepAliveListResponse>

clearKeepAliveList(params) → {Promise.<BatchTaskResponse>}

清空后台应用保活列表

Example
AndroidInstance.clearKeepAliveList({'cai-xxx1': {}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Returns:
Type
Promise.<BatchTaskResponse>

mute(params) → {Promise.<BatchTaskResponse>}

静音开关

Example
AndroidInstance.mute({'cai-xxx1': {Mute: true}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
Mute boolean

Mute

Returns:
Type
Promise.<BatchTaskResponse>

mediaSearch(params) → {Promise.<MediaSearchResponse>}

媒体库文件搜索

Example
AndroidInstance.mediaSearch({'cai-xxx1': {"Keyword": "abc"}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Properties
Name Type Description
Keyword boolean

Keyword

Returns:
Type
Promise.<MediaSearchResponse>

reboot(params) → {Promise.<BatchTaskResponse>}

静音开关

Example
AndroidInstance.reboot({'cai-xxx1': {}});
Parameters:
Name Type Description
params Object

key 为 instanceId

Properties
Name Type Description
key string

设备 instanceId

value Object

value

Returns:
Type
Promise.<BatchTaskResponse>