Appearance
监听usb状态
方法名
usbStatusListener
用法
用法如下
js
module.usbStatusListener({
success: (res : any) => {
console.log(res)
},
fail: (res : any) => {
console.log(res)
},
complete: (res : any) => {
console.log(res)
}
})参数说明
| 参数名 | 参数类型 | 是否必填 | 默认值 | 参数描述 |
|---|---|---|---|---|
| success | Function | 否 | 无 | 执行成功的函数 |
| fail | Function | 否 | 无 | 执行失败的函数 |
| complete | Function | 否 | 无 | 执行完成的函数,不管成功还是失败都会执行 |
回调
示例
json
{
"data": {
"device": {
"productName": "Web Camera",
"deviceId": 1002,
"deviceName": "/dev/bus/usb/001/002",
"vendorId": 7119,
"productId": 8833
},
"type": "onAttached"
},
"message": "",
"code": 0
}回调说明
| 参数名 | 参数类型 | 参数描述 |
|---|---|---|
| message | String | 消息提示 |
| data | Object | 数据对象 |
| data.type | String | 当前状态,onListener:监听成功,onAttached:USB插入,onDetached:USB拔出,onPermission:申请usb权限成功 |
| data.device | Object | 当前usb设备数据 |
| data.device.productId | Integer | 产品id |
| data.device.productName | String | 产品名称 |
| data.device.deviceName | String | 设备名称 |
| data.device.vendorId | Integer | 厂家id |
| data.device.deviceId | Integer | 设备id |
| code | Integer | 返回类型,0.成功,其他:失败 |