TCGSDK - AndroidInstance 子模块相关方法
需要正常 CloudGamingWebSDK
TCGSDK.init 后,再调用 AndroidInstance 相关方法
AndroidInstance 是 TCGSDK 的子模块,用于操作 Android 设备,包括的几类操作能力如下:
- 连接单个实例看到云手机画面,以及云手机各种操作
- 通过截图预览多个云手机的画面
- 其他各类功能操作

Example
const AndroidInstance = TCGSDK.AndroidInstance()
Methods
setMaster(params) → {void}
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:
transMessage(params) → {void}
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
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>}
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>
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>
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>
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>}
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>