提交 f92ffbb0 编写于 作者: Q q30043944

鸿蒙指南文档ArkTS适配

Signed-off-by: Nq30043944 <qinlong18@huawei.com>
上级 b2defeb2
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
## 导入模块 ## 导入模块
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedHardware.deviceManager';
``` ```
...@@ -43,18 +43,23 @@ createDeviceManager(bundleName: string, callback: AsyncCallback&lt;DeviceManager ...@@ -43,18 +43,23 @@ createDeviceManager(bundleName: string, callback: AsyncCallback&lt;DeviceManager
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
let dmInstance: deviceManager.Devicemanager | null = null;
try { try {
deviceManager.createDeviceManager("ohos.samples.jshelloworld", (err, data) => { deviceManager.createDeviceManager("ohos.samples.jshelloworld", (err: BusinessError, data: deviceManager.Devicemanager) => {
if (err) { if (err) {
console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message); console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
return; return;
} }
console.info("createDeviceManager success"); console.info("createDeviceManager success");
let dmInstance = data; dmInstance = data;
}); });
} catch(err) { } catch(err) {
console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("createDeviceManager errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -243,11 +248,14 @@ release(): void ...@@ -243,11 +248,14 @@ release(): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
dmInstance.release(); dmInstance.release();
} catch (err) { } catch (err) {
console.error("release errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("release errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -277,11 +285,15 @@ getTrustedDeviceListSync(): Array&lt;DeviceInfo&gt; ...@@ -277,11 +285,15 @@ getTrustedDeviceListSync(): Array&lt;DeviceInfo&gt;
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
try { try {
var deviceInfoList = dmInstance.getTrustedDeviceListSync(); let deviceInfoList: Array<deviceManager.DeviceInfo> = dmInstance.getTrustedDeviceListSync();
} catch (err) { } catch (err) {
console.error("getTrustedDeviceListSync errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getTrustedDeviceListSync errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -317,11 +329,15 @@ getTrustedDeviceListSync(isRefresh: boolean): Array&lt;DeviceInfo&gt; ...@@ -317,11 +329,15 @@ getTrustedDeviceListSync(isRefresh: boolean): Array&lt;DeviceInfo&gt;
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
try { try {
var deviceInfoList = dmInstance.getTrustedDeviceListSync(true); let deviceInfoList: Array<deviceManager.DeviceInfo> = dmInstance.getTrustedDeviceListSync(true);
} catch (err) { } catch (err) {
console.error("getTrustedDeviceListSync errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getTrustedDeviceListSync errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -343,9 +359,11 @@ getTrustedDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceInfo&gt;&gt;): voi ...@@ -343,9 +359,11 @@ getTrustedDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceInfo&gt;&gt;): voi
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
try { try {
dmInstance.getTrustedDeviceList((err, data) => { dmInstance.getTrustedDeviceList((err: BusinessError, data: deviceManager.DeviceInfo) => {
if (err) { if (err) {
console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message); console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
return; return;
...@@ -353,7 +371,8 @@ getTrustedDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceInfo&gt;&gt;): voi ...@@ -353,7 +371,8 @@ getTrustedDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceInfo&gt;&gt;): voi
console.log('get trusted device info: ' + JSON.stringify(data)); console.log('get trusted device info: ' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getTrustedDeviceList errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -375,10 +394,13 @@ getTrustedDeviceList(): Promise&lt;Array&lt;DeviceInfo&gt;&gt; ...@@ -375,10 +394,13 @@ getTrustedDeviceList(): Promise&lt;Array&lt;DeviceInfo&gt;&gt;
**示例:** **示例:**
```js ```ts
dmInstance.getTrustedDeviceList().then((data) => { import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
dmInstance.getTrustedDeviceList().then((data: Array<deviceManager.DeviceInfo>) => {
console.log('get trusted device info: ' + JSON.stringify(data)); console.log('get trusted device info: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err: BusinessError) => {
console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message); console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
}); });
``` ```
...@@ -409,11 +431,15 @@ getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo) ...@@ -409,11 +431,15 @@ getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo)
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
try { try {
var deviceInfo = dmInstance.getLocalDeviceInfoSync(); let deviceInfo: deviceManager.DeviceInfo = dmInstance.getLocalDeviceInfoSync();
} catch (err) { } catch (err) {
console.error("getLocalDeviceInfoSync errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getLocalDeviceInfoSync errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -435,9 +461,13 @@ getLocalDeviceInfo(callback:AsyncCallback&lt;DeviceInfo&gt;): void ...@@ -435,9 +461,13 @@ getLocalDeviceInfo(callback:AsyncCallback&lt;DeviceInfo&gt;): void
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
try { try {
dmInstance.getLocalDeviceInfo((err, data) => { dmInstance.getLocalDeviceInfo((err: BusinessError, data: deviceManager.DeviceInfo) => {
if (err) { if (err) {
console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message); console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
return; return;
...@@ -445,7 +475,8 @@ getLocalDeviceInfo(callback:AsyncCallback&lt;DeviceInfo&gt;): void ...@@ -445,7 +475,8 @@ getLocalDeviceInfo(callback:AsyncCallback&lt;DeviceInfo&gt;): void
console.log('get local device info: ' + JSON.stringify(data)); console.log('get local device info: ' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getLocalDeviceInfo errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -467,10 +498,13 @@ getLocalDeviceInfo(): Promise&lt;DeviceInfo&gt; ...@@ -467,10 +498,13 @@ getLocalDeviceInfo(): Promise&lt;DeviceInfo&gt;
**示例:** **示例:**
```js ```ts
dmInstance.getLocalDeviceInfo().then((data) => { import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
dmInstance.getLocalDeviceInfo().then((data: deviceManager.DeviceInfo) => {
console.log('get local device info: ' + JSON.stringify(data)); console.log('get local device info: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err: BusinessError) => {
console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message); console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
}); });
``` ```
...@@ -494,11 +528,14 @@ getDeviceInfo(networkId: string, callback:AsyncCallback&lt;DeviceInfo&gt;): void ...@@ -494,11 +528,14 @@ getDeviceInfo(networkId: string, callback:AsyncCallback&lt;DeviceInfo&gt;): void
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
try { try {
// 设备网络标识,可以从可信设备列表中获取 // 设备网络标识,可以从可信设备列表中获取
let networkId = "xxxxxxx" let networkId = "xxxxxxx"
dmInstance.getDeviceInfo(networkId, (err, data) => { dmInstance.getDeviceInfo(networkId, (err: BusinessError, data: deviceManager.DeviceInfo) => {
if (err) { if (err) {
console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message); console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
return; return;
...@@ -506,7 +543,8 @@ getDeviceInfo(networkId: string, callback:AsyncCallback&lt;DeviceInfo&gt;): void ...@@ -506,7 +543,8 @@ getDeviceInfo(networkId: string, callback:AsyncCallback&lt;DeviceInfo&gt;): void
console.log('get device info: ' + JSON.stringify(data)); console.log('get device info: ' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getDeviceInfo errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -534,12 +572,15 @@ getDeviceInfo(networkId: string): Promise&lt;DeviceInfo&gt; ...@@ -534,12 +572,15 @@ getDeviceInfo(networkId: string): Promise&lt;DeviceInfo&gt;
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
// 设备网络标识,可以从可信设备列表中获取 // 设备网络标识,可以从可信设备列表中获取
let networkId = "xxxxxxx" let networkId = "xxxxxxx"
dmInstance.getDeviceInfo(networkId).then((data) => { dmInstance.getDeviceInfo(networkId).then((data: deviceManager.DeviceInfo) => {
console.log('get device info: ' + JSON.stringify(data)); console.log('get device info: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err: BusinessError) => {
console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message); console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
}); });
``` ```
...@@ -571,22 +612,35 @@ startDeviceDiscovery(subscribeInfo: SubscribeInfo): void ...@@ -571,22 +612,35 @@ startDeviceDiscovery(subscribeInfo: SubscribeInfo): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
interface SubscribeInfo {
subscribeId: number,
mode: number, // 主动模式
medium: number, // 自动发现类型,同时支持多种发现类型
freq: number, // 高频率
isSameAccount: boolean,
isWakeRemote: boolean,
capability: number
};
// 生成发现标识,随机数确保每次调用发现接口的标识不一致 // 生成发现标识,随机数确保每次调用发现接口的标识不一致
var subscribeId = Math.floor(Math.random() * 10000 + 1000); let subscribeId = Math.floor(Math.random() * 10000 + 1000);
var subscribeInfo = { let subscribeInfo: SubscribeInfo = {
"subscribeId": subscribeId, subscribeId: subscribeId,
"mode": 0xAA, // 主动模式 mode: 0xAA, // 主动模式
"medium": 0, // 自动发现类型,同时支持多种发现类型 medium: 0, // 自动发现类型,同时支持多种发现类型
"freq": 2, // 高频率 freq: 2, // 高频率
"isSameAccount": false, isSameAccount: false,
"isWakeRemote": false, isWakeRemote: false,
"capability": 1 capability: 1
}; };
try { try {
dmInstance.startDeviceDiscovery(subscribeInfo); // 当有设备发现时,通过deviceFound回调通知给应用程序 dmInstance.startDeviceDiscovery(subscribeInfo); // 当有设备发现时,通过deviceFound回调通知给应用程序
} catch (err) { } catch (err) {
console.error("startDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("startDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -618,31 +672,57 @@ startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void ...@@ -618,31 +672,57 @@ startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
interface Filters {
type: string,
value: number
}
interface FilterOptions {
filter_op: string, // 可选, 默认"OR"
filters: Filters[]
}
interface SubscribeInfo {
subscribeId: number,
mode: number, // 主动模式
medium: number, // 自动发现类型,同时支持多种发现类型
freq: number, // 高频率
isSameAccount: boolean,
isWakeRemote: boolean,
capability: number
}
// 生成发现标识,随机数确保每次调用发现接口的标识不一致 // 生成发现标识,随机数确保每次调用发现接口的标识不一致
var subscribeId = Math.floor(Math.random() * 10000 + 1000); let subscribeId = Math.floor(Math.random() * 10000 + 1000);
var subscribeInfo = { let subscribeInfo: SubscribeInfo = {
"subscribeId": subscribeId, subscribeId: subscribeId,
"mode": 0xAA, // 主动模式 mode: 0xAA, // 主动模式
"medium": 0, // 自动发现类型,同时支持多种发现类型 medium: 0, // 自动发现类型,同时支持多种发现类型
"freq": 2, // 高频率 freq: 2, // 高频率
"isSameAccount": false, isSameAccount: false,
"isWakeRemote": false, isWakeRemote: false,
"capability": 1 capability: 1
}; };
var filterOptions = {
"filter_op": "OR", // 可选, 默认"OR" let filters: Filters[] = [
"filters": [ {
{ type: "range",
"type": "range", value: 50 // 需过滤发现设备的距离,单位(cm)
"value": 50 // 需过滤发现设备的距离,单位(cm) }
} ]
]
let filterOptions: FilterOptions = {
filter_op: "OR", // 可选, 默认"OR"
filters: filters
}; };
try { try {
dmInstance.startDeviceDiscovery(subscribeInfo, JSON.stringify(filterOptions)); // 当有设备发现时,通过deviceFound回调通知给应用程序 dmInstance.startDeviceDiscovery(subscribeInfo, JSON.stringify(filterOptions)); // 当有设备发现时,通过deviceFound回调通知给应用程序
} catch (err) { } catch (err) {
console.error("startDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("startDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -672,13 +752,16 @@ stopDeviceDiscovery(subscribeId: number): void ...@@ -672,13 +752,16 @@ stopDeviceDiscovery(subscribeId: number): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
// stopDeviceDiscovery和startDeviceDiscovery需配对使用,入参需要和startDeviceDiscovery接口传入的subscribeId值相等 // stopDeviceDiscovery和startDeviceDiscovery需配对使用,入参需要和startDeviceDiscovery接口传入的subscribeId值相等
var subscribeId = 12345; let subscribeId = 12345;
dmInstance.stopDeviceDiscovery(subscribeId); dmInstance.stopDeviceDiscovery(subscribeId);
} catch (err) { } catch (err) {
console.error("stopDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("stopDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -709,19 +792,30 @@ publishDeviceDiscovery(publishInfo: PublishInfo): void ...@@ -709,19 +792,30 @@ publishDeviceDiscovery(publishInfo: PublishInfo): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
interface PublishInfo {
publishId: number,
mode: number, // 主动模式
freq: number, // 高频率
ranging: boolean // 支持发现时测距
};
// 生成发布标识,随机数确保每次调用发布接口的标识不一致 // 生成发布标识,随机数确保每次调用发布接口的标识不一致
var publishId = Math.floor(Math.random() * 10000 + 1000); let publishId = Math.floor(Math.random() * 10000 + 1000);
var publishInfo = { let publishInfo: PublishInfo = {
"publishId": publishId, publishId: publishId,
"mode": 0xAA, // 主动模式 mode: 0xAA, // 主动模式
"freq": 2, // 高频率 freq: 2, // 高频率
"ranging": true // 支持发现时测距 ranging: true // 支持发现时测距
}; };
try { try {
dmInstance.publishDeviceDiscovery(publishInfo); // 当有发布结果时,通过回调通知给应用程序 dmInstance.publishDeviceDiscovery(publishInfo); // 当有发布结果时,通过回调通知给应用程序
} catch (err) { } catch (err) {
console.error("publishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("publishDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -751,13 +845,16 @@ unPublishDeviceDiscovery(publishId: number): void ...@@ -751,13 +845,16 @@ unPublishDeviceDiscovery(publishId: number): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
// unPublishDeviceDiscovery和publishDeviceDiscovery配对使用,入参需要和publishDeviceDiscovery接口传入的publishId值相等 // unPublishDeviceDiscovery和publishDeviceDiscovery配对使用,入参需要和publishDeviceDiscovery接口传入的publishId值相等
var publishId = 12345; let publishId = 12345;
dmInstance.unPublishDeviceDiscovery(publishId); dmInstance.unPublishDeviceDiscovery(publishId);
} catch (err) { } catch (err) {
console.error("unPublishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("unPublishDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -781,27 +878,55 @@ authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: Async ...@@ -781,27 +878,55 @@ authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: Async
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
deviceId: string = ""
pinToken?: number = 0
}
interface DeviceInfo {
deviceId: string,
deviceName: string
deviceType: number,
networkId: string,
range: number
};
interface ExtraInfo {
targetPkgName: string,
appName: string,
appDescription: string,
business: string
}
interface AuthParam {
authType: number,// 认证类型: 1 - 无帐号PIN码认证
extraInfo: ExtraInfo
}
// 认证的设备信息,可以从发现的结果中获取 // 认证的设备信息,可以从发现的结果中获取
var deviceInfo ={ let deviceInfo: DeviceInfo = {
"deviceId": "XXXXXXXX", deviceId: "XXXXXXXX",
"deviceName": "", deviceName: "",
"deviceType": 0x0E, deviceType: 0x0E,
"networkId" : "xxxxxxx", networkId: "xxxxxxx",
"range" : 0 range: 0
}; };
let extraInfo = { let extraInfo: ExtraInfo = {
'targetPkgName': 'ohos.samples.xxx', targetPkgName: 'ohos.samples.xxx',
'appName': 'xxx', appName: 'xxx',
'appDescription': 'xxx', appDescription: 'xxx',
'business': '0' business: '0'
} }
let authParam = { let authParam: AuthParam = {
'authType': 1,// 认证类型: 1 - 无帐号PIN码认证 authType: 1,// 认证类型: 1 - 无帐号PIN码认证
'extraInfo': extraInfo extraInfo: extraInfo
} }
try { try {
dmInstance.authenticateDevice(deviceInfo, authParam, (err, data) => { dmInstance.authenticateDevice(deviceInfo, authParam, (err: BusinessError, data: Data) => {
if (err) { if (err) {
console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message); console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
return; return;
...@@ -810,7 +935,8 @@ authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: Async ...@@ -810,7 +935,8 @@ authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: Async
let token = data.pinToken; let token = data.pinToken;
}); });
} catch (err) { } catch (err) {
console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("authenticateDevice errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -840,18 +966,29 @@ unAuthenticateDevice(deviceInfo: DeviceInfo): void ...@@ -840,18 +966,29 @@ unAuthenticateDevice(deviceInfo: DeviceInfo): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
interface DeviceInfo {
deviceId: string,
deviceName: string,
deviceType: number,
networkId: string,
range: number
}
try { try {
var deviceInfo ={ let deviceInfo: DeviceInfo = {
"deviceId": "XXXXXXXX", deviceId: "XXXXXXXX",
"deviceName": "", deviceName: "",
"deviceType": 0x0E, deviceType: 0x0E,
"networkId" : "xxxxxxx", networkId: "xxxxxxx",
"range" : 0 range: 0
}; };
dmInstance.unAuthenticateDevice(deviceInfo); dmInstance.unAuthenticateDevice(deviceInfo);
} catch (err) { } catch (err) {
console.error("unAuthenticateDevice errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("unAuthenticateDevice errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -874,22 +1011,46 @@ verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback&lt;{deviceId: string, ...@@ -874,22 +1011,46 @@ verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback&lt;{deviceId: string,
**示例:** **示例:**
```js ```ts
let authInfo = { import { BusinessError } from '@ohos.base'
"authType": 1,
"token": 123456, interface ExtraInfo {
"extraInfo": {} authType: number,
token: number
}
interface AuthInfo {
authType: number,
token: number,
extraInfo: ExtraInfo
}
class Data {
deviceId: string = ""
level: number = 0
}
let extraInfo: ExtraInfo = {
authType: 0,
token: 0
}
let authInfo: AuthInfo = {
authType: 1,
token: 123456,
extraInfo: extraInfo
} }
try { try {
dmInstance.verifyAuthInfo(authInfo, (err, data) => { dmInstance.verifyAuthInfo(authInfo, (err: BusinessError, data: Data) => {
if (err) { if (err) {
console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message); console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
return; return;
} }
console.info("verifyAuthInfo result:" + JSON.stringify(data)); console.info("verifyAuthInfo result:" + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("verifyAuthInfo errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -912,7 +1073,9 @@ setUserOperation(operateAction: number, params: string): void; ...@@ -912,7 +1073,9 @@ setUserOperation(operateAction: number, params: string): void;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
/* /*
operateAction = 0 - 允许授权 operateAction = 0 - 允许授权
...@@ -925,7 +1088,8 @@ setUserOperation(operateAction: number, params: string): void; ...@@ -925,7 +1088,8 @@ setUserOperation(operateAction: number, params: string): void;
let operation = 0; let operation = 0;
dmInstance.setUserOperation(operation, "extra") dmInstance.setUserOperation(operation, "extra")
} catch (err) { } catch (err) {
console.error("setUserOperation errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("setUserOperation errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -948,13 +1112,25 @@ requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{regi ...@@ -948,13 +1112,25 @@ requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{regi
**示例:** **示例:**
```js ```ts
let credentialInfo = { import { BusinessError } from '@ohos.base'
"version" : "1.2.3",
"userId" : "123" interface CredentialInfo {
version: string,
userId: string
} }
class Data {
registerInfo: string = ""
}
let credentialInfo: CredentialInfo = {
version: "1.2.3",
userId: "123"
}
try { try {
dmInstance.requestCredentialRegisterInfo(credentialInfo, (data) => { dmInstance.requestCredentialRegisterInfo(credentialInfo, (dataData) => {
if (data) { if (data) {
console.info("requestCredentialRegisterInfo result:" + JSON.stringify(data)); console.info("requestCredentialRegisterInfo result:" + JSON.stringify(data));
} else { } else {
...@@ -962,7 +1138,8 @@ requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{regi ...@@ -962,7 +1138,8 @@ requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{regi
} }
}); });
} catch (err) { } catch (err) {
console.error("requestCredentialRegisterInfo err:" + err.code + "," + err.message); let e: BusinessError = err as BusinessError;
console.error("requestCredentialRegisterInfo err:" + e.code + "," + e.message);
} }
``` ```
...@@ -985,29 +1162,57 @@ importCredential(credentialInfo: string, callback: AsyncCallback<{resultInfo: st ...@@ -985,29 +1162,57 @@ importCredential(credentialInfo: string, callback: AsyncCallback<{resultInfo: st
**示例:** **示例:**
```js ```ts
let credentialInfo = { import { BusinessError } from '@ohos.base'
"processType" : 1,
"authType" : 1, class Data {
"userId" : "123", resultInfo: string = ""
"deviceId" : "aaa",
"version" : "1.2.3",
"devicePk" : "0000",
"credentialData" :
[
{
"credentialType" : 2,
"credentialId" : "102",
"serverPk" : "3059301306072A8648CE3D020106082A8648CE3D03",
"pkInfoSignature" : "30440220490BCB4F822004C9A76AB8D97F80041FC0E",
"pkInfo" : "",
"authCode" : "",
"peerDeviceId" : ""
}
]
} }
interface CredentialData {
credentialType: number,
credentialId: string,
serverPk: string,
pkInfoSignature : string,
pkInfo: string,
authCode: string,
peerDeviceId: string
}
interface CredentialInfo {
processType: number,
authType: number,
userId: string,
deviceId: string,
version: string,
devicePk : string,
credentialData : CredentialData[]
}
let credentialData: CredentialData = [
{
credentialType: 2,
credentialId: "102",
serverPk: "3059301306072A8648CE3D020106082A8648CE3D03",
pkInfoSignature : "30440220490BCB4F822004C9A76AB8D97F80041FC0E",
pkInfo: "",
authCode: "",
peerDeviceId: ""
}
]
let credentialInfo: CredentialInfo = {
processType: 1,
authType: 1,
userId: "123",
deviceId: "aaa",
version: "1.2.3",
devicePk : "0000",
credentialData : credentialData
}
try { try {
dmInstance.importCredential(credentialInfo, (data) => { dmInstance.importCredential(credentialInfo, (data: Data) => {
if (data) { if (data) {
console.info("importCredential result:" + JSON.stringify(data)); console.info("importCredential result:" + JSON.stringify(data));
} else { } else {
...@@ -1015,7 +1220,8 @@ importCredential(credentialInfo: string, callback: AsyncCallback<{resultInfo: st ...@@ -1015,7 +1220,8 @@ importCredential(credentialInfo: string, callback: AsyncCallback<{resultInfo: st
} }
}); });
} catch (err) { } catch (err) {
console.error("importCredential err:" + err.code + "," + err.message); let e: BusinessError = err as BusinessError;
console.error("importCredential err:" + e.code + "," + e.message);
} }
``` ```
...@@ -1038,14 +1244,27 @@ deleteCredential(queryInfo: string, callback: AsyncCallback<{resultInfo: string} ...@@ -1038,14 +1244,27 @@ deleteCredential(queryInfo: string, callback: AsyncCallback<{resultInfo: string}
**示例:** **示例:**
```js ```ts
let queryInfo = { import { BusinessError } from '@ohos.base'
"processType" : 1,
"authType" : 1, class Data {
"userId" : "123" resultInfo: string = ""
}
interface QueryInfo {
processType: number,
authType: number,
userId: string
}
let queryInfo: QueryInfo = {
processType: 1,
authType: 1,
userId: "123"
} }
try { try {
dmInstance.deleteCredential(queryInfo, (data) => { dmInstance.deleteCredential(queryInfo, (data: Data) => {
if (data) { if (data) {
console.info("deleteCredential result:" + JSON.stringify(data)); console.info("deleteCredential result:" + JSON.stringify(data));
} else { } else {
...@@ -1053,7 +1272,8 @@ deleteCredential(queryInfo: string, callback: AsyncCallback<{resultInfo: string} ...@@ -1053,7 +1272,8 @@ deleteCredential(queryInfo: string, callback: AsyncCallback<{resultInfo: string}
} }
}); });
} catch (err) { } catch (err) {
console.error("deleteCredential err:" + err.code + "," + err.message); let e: BusinessError = err as BusinessError;
console.error("deleteCredential err:" + e.code + "," + e.message);
} }
``` ```
...@@ -1076,16 +1296,27 @@ ui状态变更回调。 ...@@ -1076,16 +1296,27 @@ ui状态变更回调。
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
param: string = ""
}
interface TmpStr {
verifyFailed: boolean
}
try { try {
dmInstance.on('uiStateChange', (data) => { dmInstance.on('uiStateChange', (data: Data) => {
console.log("uiStateChange executed, dialog closed" + JSON.stringify(data)) console.log("uiStateChange executed, dialog closed" + JSON.stringify(data))
var tmpStr = JSON.parse(data.param) let tmpStr: TmpStr = JSON.parse(data.param)
var isShow = tmpStr.verifyFailed let isShow = tmpStr.verifyFailed
console.log("uiStateChange executed, dialog closed" + isShow) console.log("uiStateChange executed, dialog closed" + isShow)
}); });
} catch (err) { } catch (err) {
console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("uiStateChange errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1108,11 +1339,14 @@ off(type: 'uiStateChange', callback?: Callback&lt;{ param: string}&gt;): void; ...@@ -1108,11 +1339,14 @@ off(type: 'uiStateChange', callback?: Callback&lt;{ param: string}&gt;): void;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
dmInstance.off('uiStateChange'); dmInstance.off('uiStateChange');
} catch (err) { } catch (err) {
console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("uiStateChange errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1135,13 +1369,22 @@ on(type: 'deviceStateChange', callback: Callback&lt;{ action: DeviceStateChange ...@@ -1135,13 +1369,22 @@ on(type: 'deviceStateChange', callback: Callback&lt;{ action: DeviceStateChange
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
class Data {
action: deviceManager.DeviceStateChangeAction = 0
device: deviceManager.DeviceInfo = {}
}
try { try {
dmInstance.on('deviceStateChange', (data) => { dmInstance.on('deviceStateChange', (data: Data) => {
console.info("deviceStateChange on:" + JSON.stringify(data)); console.info("deviceStateChange on:" + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("deviceStateChange errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1164,13 +1407,22 @@ off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChang ...@@ -1164,13 +1407,22 @@ off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChang
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
class Data {
action: deviceManager.DeviceStateChangeAction = 0
device: deviceManager.DeviceInfo = {}
}
try { try {
dmInstance.off('deviceStateChange', (data) => { dmInstance.off('deviceStateChange', (data: Data) => {
console.info('deviceStateChange' + JSON.stringify(data)); console.info('deviceStateChange' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("deviceStateChange errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1193,13 +1445,23 @@ on(type: 'deviceFound', callback: Callback&lt;{ subscribeId: number, device: Dev ...@@ -1193,13 +1445,23 @@ on(type: 'deviceFound', callback: Callback&lt;{ subscribeId: number, device: Dev
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
class Data {
subscribeId: number = 0
device: deviceManager.DeviceInfo = {}
}
subscribeId: number, device: DeviceInfo
try { try {
dmInstance.on('deviceFound', (data) => { dmInstance.on('deviceFound', (data: Data) => {
console.info("deviceFound:" + JSON.stringify(data)); console.info("deviceFound:" + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("deviceFound errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1222,13 +1484,22 @@ off(type: 'deviceFound', callback?: Callback&lt;{ subscribeId: number, device: D ...@@ -1222,13 +1484,22 @@ off(type: 'deviceFound', callback?: Callback&lt;{ subscribeId: number, device: D
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import { BusinessError } from '@ohos.base'
class Data {
subscribeId: number = 0
device: deviceManager.DeviceInfo = {}
}
try { try {
dmInstance.off('deviceFound', (data) => { dmInstance.off('deviceFound', (data: Data) => {
console.info('deviceFound' + JSON.stringify(data)); console.info('deviceFound' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("deviceFound errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1251,13 +1522,21 @@ on(type: 'discoverFail', callback: Callback&lt;{ subscribeId: number, reason: nu ...@@ -1251,13 +1522,21 @@ on(type: 'discoverFail', callback: Callback&lt;{ subscribeId: number, reason: nu
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
subscribeId: number = 0
reason: number = 0
}
try { try {
dmInstance.on('discoverFail', (data) => { dmInstance.on('discoverFail', (data: Data) => {
console.info("discoverFail on:" + JSON.stringify(data)); console.info("discoverFail on:" + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("discoverFail errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("discoverFail errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1280,13 +1559,21 @@ off(type: 'discoverFail', callback?: Callback&lt;{ subscribeId: number, reason: ...@@ -1280,13 +1559,21 @@ off(type: 'discoverFail', callback?: Callback&lt;{ subscribeId: number, reason:
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
subscribeId: number = 0
reason: number = 0
}
try { try {
dmInstance.off('discoverFail', (data) => { dmInstance.off('discoverFail', (data: Data) => {
console.info('discoverFail' + JSON.stringify(data)); console.info('discoverFail' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("discoverFail errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("discoverFail errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1310,13 +1597,20 @@ on(type: 'publishSuccess', callback: Callback&lt;{ publishId: number }&gt;): voi ...@@ -1310,13 +1597,20 @@ on(type: 'publishSuccess', callback: Callback&lt;{ publishId: number }&gt;): voi
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
publishId: number = 0
}
try { try {
dmInstance.on('publishSuccess', (data) => { dmInstance.on('publishSuccess', (data: Data) => {
console.info("publishSuccess:" + JSON.stringify(data)); console.info("publishSuccess:" + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("publishSuccess errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1339,13 +1633,20 @@ off(type: 'publishSuccess', callback?: Callback&lt;{ publishId: number }&gt;): v ...@@ -1339,13 +1633,20 @@ off(type: 'publishSuccess', callback?: Callback&lt;{ publishId: number }&gt;): v
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
publishId: number = 0
}
try { try {
dmInstance.off('publishSuccess', (data) => { dmInstance.off('publishSuccess', (data: Data) => {
console.info('publishSuccess' + JSON.stringify(data)); console.info('publishSuccess' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("publishSuccess errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1368,13 +1669,21 @@ on(type: 'publishFail', callback: Callback&lt;{ publishId: number, reason: numbe ...@@ -1368,13 +1669,21 @@ on(type: 'publishFail', callback: Callback&lt;{ publishId: number, reason: numbe
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
publishId: number = 0
reason: number = 0
}
try { try {
dmInstance.on('publishFail', (data) => { dmInstance.on('publishFail', (data: Data) => {
console.info("publishFail on:" + JSON.stringify(data)); console.info("publishFail on:" + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("publishFail errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("publishFail errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1397,13 +1706,21 @@ off(type: 'publishFail', callback?: Callback&lt;{ publishId: number, reason: num ...@@ -1397,13 +1706,21 @@ off(type: 'publishFail', callback?: Callback&lt;{ publishId: number, reason: num
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
publishId: number = 0
reason: number = 0
}
try { try {
dmInstance.off('publishFail', (data) => { dmInstance.off('publishFail', (data: Data) => {
console.info('publishFail' + JSON.stringify(data)); console.info('publishFail' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("publishFail errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("publishFail errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1426,13 +1743,16 @@ on(type: 'serviceDie', callback: () =&gt; void): void ...@@ -1426,13 +1743,16 @@ on(type: 'serviceDie', callback: () =&gt; void): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
dmInstance.on("serviceDie", () => { dmInstance.on("serviceDie", () => {
console.info("serviceDie on"); console.info("serviceDie on");
}); });
} catch (err) { } catch (err) {
console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("serviceDie errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -1455,12 +1775,15 @@ off(type: 'serviceDie', callback?: () =&gt; void): void ...@@ -1455,12 +1775,15 @@ off(type: 'serviceDie', callback?: () =&gt; void): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
dmInstance.off("serviceDie", () => { dmInstance.off("serviceDie", () => {
console.info("serviceDie off"); console.info("serviceDie off");
}); });
} catch (err) { } catch (err) {
console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("serviceDie errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
\ No newline at end of file
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
## 导入模块 ## 导入模块
```js ```ts
import deviceManager from '@ohos.distributedDeviceManager'; import deviceManager from '@ohos.distributedDeviceManager';
``` ```
...@@ -45,11 +45,15 @@ createDeviceManager(bundleName: string): DeviceManager; ...@@ -45,11 +45,15 @@ createDeviceManager(bundleName: string): DeviceManager;
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedDeviceManager'
import { BusinessError } from '@ohos.base'
try { try {
let dmInstance = deviceManager.createDeviceManager("ohos.samples.jshelloworld"); let dmInstance = deviceManager.createDeviceManager("ohos.samples.jshelloworld");
} catch(err) { } catch(err) {
console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("createDeviceManager errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -79,11 +83,14 @@ releaseDeviceManager(deviceManager: DeviceManager): void; ...@@ -79,11 +83,14 @@ releaseDeviceManager(deviceManager: DeviceManager): void;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
deviceManager.releaseDeviceManager(dmInstance); deviceManager.releaseDeviceManager(dmInstance);
} catch (err) { } catch (err) {
console.error("release device manager errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("release device manager errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -143,11 +150,15 @@ getAvailableDeviceListSync(): Array&lt;DeviceBasicInfo&gt;; ...@@ -143,11 +150,15 @@ getAvailableDeviceListSync(): Array&lt;DeviceBasicInfo&gt;;
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedDeviceManager'
import { BusinessError } from '@ohos.base'
try { try {
var deviceInfoList = dmInstance.getAvailableDeviceListSync(); let deviceInfoList: Array<deviceManager.eviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
} catch (err) { } catch (err) {
console.error("getAvailableDeviceListSync errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getAvailableDeviceListSync errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -177,9 +188,12 @@ getAvailableDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceBasicInfo&gt;&gt ...@@ -177,9 +188,12 @@ getAvailableDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceBasicInfo&gt;&gt
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedDeviceManager'
import { BusinessError } from '@ohos.base'
try { try {
dmInstance.getAvailableDeviceList((err, data) => { dmInstance.getAvailableDeviceList((err: BusinessError, data: Array<deviceManager.DeviceBasicInfo>) => {
if (err) { if (err) {
console.error("getAvailableDeviceList errCode:" + err.code + ",errMessage:" + err.message); console.error("getAvailableDeviceList errCode:" + err.code + ",errMessage:" + err.message);
return; return;
...@@ -187,7 +201,8 @@ getAvailableDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceBasicInfo&gt;&gt ...@@ -187,7 +201,8 @@ getAvailableDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceBasicInfo&gt;&gt
console.log('get available device info: ' + JSON.stringify(data)); console.log('get available device info: ' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("getAvailableDeviceList errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getAvailableDeviceList errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -217,10 +232,13 @@ getAvailableDeviceList(): Promise&lt;Array&lt;DeviceBasicInfo&gt;&gt;; ...@@ -217,10 +232,13 @@ getAvailableDeviceList(): Promise&lt;Array&lt;DeviceBasicInfo&gt;&gt;;
**示例:** **示例:**
```js ```ts
dmInstance.getAvailableDeviceList().then((data) => { import deviceManager from '@ohos.distributedDeviceManager'
import { BusinessError } from '@ohos.base'
dmInstance.getAvailableDeviceList().then((data: Array<deviceManager.DeviceBasicInfo>) => {
console.log('get available device info: ' + JSON.stringify(data)); console.log('get available device info: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err: BusinessError) => {
console.error("getAvailableDeviceList errCode:" + err.code + ",errMessage:" + err.message); console.error("getAvailableDeviceList errCode:" + err.code + ",errMessage:" + err.message);
}); });
``` ```
...@@ -251,12 +269,15 @@ getLocalDeviceNetworkId(): string; ...@@ -251,12 +269,15 @@ getLocalDeviceNetworkId(): string;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
var deviceNetworkId = dmInstance.getLocalDeviceNetworkId(); let deviceNetworkId: string = dmInstance.getLocalDeviceNetworkId();
console.log('local device networkId: ' + JSON.stringify(deviceNetworkId)); console.log('local device networkId: ' + JSON.stringify(deviceNetworkId));
} catch (err) { } catch (err) {
console.error("getLocalDeviceNetworkId errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getLocalDeviceNetworkId errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -286,12 +307,15 @@ getLocalDeviceName(): string; ...@@ -286,12 +307,15 @@ getLocalDeviceName(): string;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
var deviceName = dmInstance.getLocalDeviceName(); let deviceName: string = dmInstance.getLocalDeviceName();
console.log('local device name: ' + JSON.stringify(deviceName)); console.log('local device name: ' + JSON.stringify(deviceName));
} catch (err) { } catch (err) {
console.error("getLocalDeviceName errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getLocalDeviceName errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -321,12 +345,15 @@ getLocalDeviceType(): number; ...@@ -321,12 +345,15 @@ getLocalDeviceType(): number;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
var deviceType = dmInstance.getLocalDeviceType(); let deviceType: number = dmInstance.getLocalDeviceType();
console.log('local device type: ' + JSON.stringify(deviceType)); console.log('local device type: ' + JSON.stringify(deviceType));
} catch (err) { } catch (err) {
console.error("getLocalDeviceType errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getLocalDeviceType errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -356,12 +383,15 @@ getLocalDeviceId(): string; ...@@ -356,12 +383,15 @@ getLocalDeviceId(): string;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
var deviceId = dmInstance.getLocalDeviceId(); let deviceId: string = dmInstance.getLocalDeviceId();
console.log('local device id: ' + JSON.stringify(deviceId)); console.log('local device id: ' + JSON.stringify(deviceId));
} catch (err) { } catch (err) {
console.error("getLocalDeviceId errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getLocalDeviceId errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -397,14 +427,17 @@ getDeviceName(networkId: string): string; ...@@ -397,14 +427,17 @@ getDeviceName(networkId: string): string;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
// 设备网络标识,可以从可信设备列表中获取 // 设备网络标识,可以从可信设备列表中获取
let networkId = "xxxxxxx" let networkId = "xxxxxxx"
var deviceName = dmInstance.getDeviceName(networkId); let deviceName: string = dmInstance.getDeviceName(networkId);
console.log('device name: ' + JSON.stringify(deviceName)); console.log('device name: ' + JSON.stringify(deviceName));
} catch (err) { } catch (err) {
console.error("getDeviceName errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getDeviceName errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -440,14 +473,17 @@ getDeviceType(networkId: string): number; ...@@ -440,14 +473,17 @@ getDeviceType(networkId: string): number;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
// 设备网络标识,可以从可信设备列表中获取 // 设备网络标识,可以从可信设备列表中获取
let networkId = "xxxxxxx" let networkId = "xxxxxxx"
var deviceType = dmInstance.getDeviceType(networkId); let deviceType: number = dmInstance.getDeviceType(networkId);
console.log('device type: ' + JSON.stringify(deviceType)); console.log('device type: ' + JSON.stringify(deviceType));
} catch (err) { } catch (err) {
console.error("getDeviceType errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("getDeviceType errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -479,20 +515,36 @@ startDiscovering(discoverParam: {[key:&nbsp;string]:&nbsp;Object} , filterOption ...@@ -479,20 +515,36 @@ startDiscovering(discoverParam: {[key:&nbsp;string]:&nbsp;Object} , filterOption
**示例:** **示例:**
```js ```ts
var discoverParam = { import { BusinessError } from '@ohos.base'
'discoverTargetType': 1
interface DiscoverParam {
discoverTargetType: number
}
interface FilterOptions {
availableStatus: number,
discoverDistance: number,
authenticationStatus: number,
authorizationType: number
}
let discoverParam: DiscoverParam = {
discoverTargetType: 1
}; };
var filterOptions = {
'availableStatus': 1, let filterOptions: FilterOptions = {
'discoverDistance': 50, availableStatus: 1,
'authenticationStatus': 0, discoverDistance: 50,
'authorizationType': 0 authenticationStatus: 0,
authorizationType: 0
}; };
try { try {
dmInstance.startDiscovering(discoverParam, filterOptions); // 当有设备发现时,通过discoverSuccess回调通知给应用程序 dmInstance.startDiscovering(discoverParam, filterOptions); // 当有设备发现时,通过discoverSuccess回调通知给应用程序
} catch (err) { } catch (err) {
console.error("startDiscovering errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("startDiscovering errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -517,11 +569,14 @@ stopDiscovering(): void; ...@@ -517,11 +569,14 @@ stopDiscovering(): void;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
dmInstance.stopDiscovering(); dmInstance.stopDiscovering();
} catch (err) { } catch (err) {
console.error("stopDiscovering errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("stopDiscovering errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -554,18 +609,32 @@ bindTarget(deviceId: string, bindParam: {[key:&nbsp;string]:&nbsp;Object} , call ...@@ -554,18 +609,32 @@ bindTarget(deviceId: string, bindParam: {[key:&nbsp;string]:&nbsp;Object} , call
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
deviceId: string = ""
}
interface BindParam {
bindType: number, // 认证类型: 1 - 无帐号PIN码认证
targetPkgName: string,
appName: string,
appOperation: string,
customDescription: string
}
// 认证的设备信息,可以从发现的结果中获取 // 认证的设备信息,可以从发现的结果中获取
var deviceId ="XXXXXXXX"; let deviceId = "XXXXXXXX";
let bindParam = { let bindParam: BindParam = {
'bindType': 1,// 认证类型: 1 - 无帐号PIN码认证 bindType: 1, // 认证类型: 1 - 无帐号PIN码认证
'targetPkgName': 'xxxx', targetPkgName: 'xxxx',
'appName': 'xxxx', appName: 'xxxx',
'appOperation': 'xxxx', appOperation: 'xxxx',
'customDescription': 'xxxx' customDescription: 'xxxx'
} }
try { try {
dmInstance.bindTarget(deviceId, bindParam, (err, data) => { dmInstance.bindTarget(deviceId, bindParam, (err: BusinessError, data: Data) => {
if (err) { if (err) {
console.error("bindTarget errCode:" + err.code + ",errMessage:" + err.message); console.error("bindTarget errCode:" + err.code + ",errMessage:" + err.message);
return; return;
...@@ -573,7 +642,8 @@ bindTarget(deviceId: string, bindParam: {[key:&nbsp;string]:&nbsp;Object} , call ...@@ -573,7 +642,8 @@ bindTarget(deviceId: string, bindParam: {[key:&nbsp;string]:&nbsp;Object} , call
console.info("bindTarget result:" + JSON.stringify(data)); console.info("bindTarget result:" + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("bindTarget errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("bindTarget errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -603,12 +673,15 @@ unbindTarget(deviceId: string): void; ...@@ -603,12 +673,15 @@ unbindTarget(deviceId: string): void;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
var deviceId ="XXXXXXXX"; let deviceId = "XXXXXXXX";
dmInstance.unbindTarget(deviceId); dmInstance.unbindTarget(deviceId);
} catch (err) { } catch (err) {
console.error("unbindTarget errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("unbindTarget errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -633,7 +706,9 @@ replyUiAction(action: number, actionResult: string): void; ...@@ -633,7 +706,9 @@ replyUiAction(action: number, actionResult: string): void;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
/* /*
action = 0 - 允许授权 action = 0 - 允许授权
...@@ -646,7 +721,8 @@ replyUiAction(action: number, actionResult: string): void; ...@@ -646,7 +721,8 @@ replyUiAction(action: number, actionResult: string): void;
let operation = 0; let operation = 0;
dmInstance.replyUiAction(operation, "extra") dmInstance.replyUiAction(operation, "extra")
} catch (err) { } catch (err) {
console.error("replyUiAction errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("replyUiAction errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -671,16 +747,27 @@ on(type: 'replyResult', callback: Callback&lt;{ param: string}&gt;): void; ...@@ -671,16 +747,27 @@ on(type: 'replyResult', callback: Callback&lt;{ param: string}&gt;): void;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
param: string = ""
}
interface TmpStr {
verifyFailed: boolean
}
try { try {
dmInstance.on('replyResult', (data) => { dmInstance.on('replyResult', (data: Data) => {
console.log("replyResult executed, dialog closed" + JSON.stringify(data)) console.log("replyResult executed, dialog closed" + JSON.stringify(data))
var tmpStr = JSON.parse(data.param) let tmpStr: TmpStr = JSON.parse(data.param)
var isShow = tmpStr.verifyFailed let isShow = tmpStr.verifyFailed
console.log("replyResult executed, dialog closed" + isShow) console.log("replyResult executed, dialog closed" + isShow)
}); });
} catch (err) { } catch (err) {
console.error("replyResult errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("replyResult errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -705,11 +792,14 @@ off(type: 'replyResult', callback?: Callback&lt;{ param: string}&gt;): void; ...@@ -705,11 +792,14 @@ off(type: 'replyResult', callback?: Callback&lt;{ param: string}&gt;): void;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
dmInstance.off('replyResult'); dmInstance.off('replyResult');
} catch (err) { } catch (err) {
console.error("replyResult errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("replyResult errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -732,13 +822,22 @@ on(type: 'deviceStateChange', callback: Callback&lt;{ action: DeviceStateChange, ...@@ -732,13 +822,22 @@ on(type: 'deviceStateChange', callback: Callback&lt;{ action: DeviceStateChange,
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedDeviceManager'
import { BusinessError } from '@ohos.base'
class Data {
action: deviceManager.DeviceStateChange = 0
device: deviceManager.DeviceBasicInfo = {}
}
try { try {
dmInstance.on('deviceStateChange', (data) => { dmInstance.on('deviceStateChange', (data: Data) => {
console.info("deviceStateChange on:" + JSON.stringify(data)); console.info("deviceStateChange on:" + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("deviceStateChange errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -761,13 +860,22 @@ off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChang ...@@ -761,13 +860,22 @@ off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChang
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedDeviceManager'
import { BusinessError } from '@ohos.base'
class Data {
action: deviceManager.DeviceStateChange = 0
device: deviceManager.DeviceBasicInfo = {}
}
try { try {
dmInstance.off('deviceStatusChange', (data) => { dmInstance.off('deviceStatusChange', (data: Data) => {
console.info('deviceStatusChange' + JSON.stringify(data)); console.info('deviceStatusChange' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("deviceStatusChange errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("deviceStatusChange errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -790,13 +898,21 @@ on(type: 'discoverSuccess', callback: Callback&lt;{ device: DeviceBasicInfo }&gt ...@@ -790,13 +898,21 @@ on(type: 'discoverSuccess', callback: Callback&lt;{ device: DeviceBasicInfo }&gt
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedDeviceManager'
import { BusinessError } from '@ohos.base'
class Data {
device: deviceManager.DeviceBasicInfo = {}
}
try { try {
dmInstance.on('discoverSuccess', (data) => { dmInstance.on('discoverSuccess', (data: Data) => {
console.info("discoverSuccess:" + JSON.stringify(data)); console.info("discoverSuccess:" + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("discoverSuccess errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("discoverSuccess errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -819,13 +935,21 @@ off(type: 'discoverSuccess', callback?: Callback&lt;{ device: DeviceBasicInfo }& ...@@ -819,13 +935,21 @@ off(type: 'discoverSuccess', callback?: Callback&lt;{ device: DeviceBasicInfo }&
**示例:** **示例:**
```js ```ts
import deviceManager from '@ohos.distributedDeviceManager'
import { BusinessError } from '@ohos.base'
class Data {
device: deviceManager.DeviceBasicInfo = {}
}
try { try {
dmInstance.off('discoverSuccess', (data) => { dmInstance.off('discoverSuccess', (data: Data) => {
console.info('discoverSuccess' + JSON.stringify(data)); console.info('discoverSuccess' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("discoverSuccess errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("discoverSuccess errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -848,13 +972,20 @@ on(type: 'deviceNameChange', callback: Callback&lt;{ deviceName: string }&gt;): ...@@ -848,13 +972,20 @@ on(type: 'deviceNameChange', callback: Callback&lt;{ deviceName: string }&gt;):
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
deviceName: string = ""
}
try { try {
dmInstance.on('deviceNameChange', (data) => { dmInstance.on('deviceNameChange', (data: Data) => {
console.info("deviceNameChange on:" + JSON.stringify(data)); console.info("deviceNameChange on:" + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("deviceNameChange errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("deviceNameChange errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -877,13 +1008,20 @@ off(type: 'deviceNameChange', callback?: Callback&lt;{ deviceName: string }&gt;) ...@@ -877,13 +1008,20 @@ off(type: 'deviceNameChange', callback?: Callback&lt;{ deviceName: string }&gt;)
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
deviceName: string = ""
}
try { try {
dmInstance.off('deviceNameChange', (data) => { dmInstance.off('deviceNameChange', (data: Data) => {
console.info('deviceNameChange' + JSON.stringify(data)); console.info('deviceNameChange' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("deviceNameChange errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("deviceNameChange errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -906,13 +1044,20 @@ on(type: 'discoverFailure', callback: Callback&lt;{ reason: number }&gt;): void; ...@@ -906,13 +1044,20 @@ on(type: 'discoverFailure', callback: Callback&lt;{ reason: number }&gt;): void;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
reason: number = 0
}
try { try {
dmInstance.on('discoverFailure', (data) => { dmInstance.on('discoverFailure', (data: Data) => {
console.info("discoverFailure on:" + JSON.stringify(data)); console.info("discoverFailure on:" + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("discoverFailure errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("discoverFailure errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -935,13 +1080,20 @@ off(type: 'discoverFailure', callback?: Callback&lt;{ reason: number }&gt;): voi ...@@ -935,13 +1080,20 @@ off(type: 'discoverFailure', callback?: Callback&lt;{ reason: number }&gt;): voi
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
class Data {
reason: number = 0
}
try { try {
dmInstance.off('discoverFailure', (data) => { dmInstance.off('discoverFailure', (data: Data) => {
console.info('discoverFailure' + JSON.stringify(data)); console.info('discoverFailure' + JSON.stringify(data));
}); });
} catch (err) { } catch (err) {
console.error("discoverFailure errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("discoverFailure errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -964,13 +1116,16 @@ on(type: 'serviceDie', callback?: Callback&lt;{}&gt;): void; ...@@ -964,13 +1116,16 @@ on(type: 'serviceDie', callback?: Callback&lt;{}&gt;): void;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
dmInstance.on("serviceDie", () => { dmInstance.on("serviceDie", () => {
console.info("serviceDie on"); console.info("serviceDie on");
}); });
} catch (err) { } catch (err) {
console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("serviceDie errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
...@@ -993,13 +1148,15 @@ off(type: 'serviceDie', callback?: Callback&lt;{}&gt;): void; ...@@ -993,13 +1148,15 @@ off(type: 'serviceDie', callback?: Callback&lt;{}&gt;): void;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base'
try { try {
dmInstance.off("serviceDie", () => { dmInstance.off("serviceDie", () => {
console.info("serviceDie off"); console.info("serviceDie off");
}); });
} catch (err) { } catch (err) {
console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message); let e: BusinessError = err as BusinessError;
console.error("serviceDie errCode:" + e.code + ",errMessage:" + e.message);
} }
``` ```
\ No newline at end of file
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册