js-apis-device-manager.md 45.6 KB
Newer Older
1
# @ohos.distributedHardware.deviceManager (设备管理)
Z
zengyawen 已提交
2

3 4 5 6 7 8 9 10 11
本模块提供分布式设备管理能力。

系统应用可调用接口实现如下功能:

- 注册和解除注册设备上下线变化监听
- 发现周边不可信设备
- 认证和取消认证设备
- 查询可信设备列表
- 查询本地设备信息,包括设备名称,设备类型和设备标识
S
summer8999 已提交
12
- 发布设备发现
S
summer8999 已提交
13

14 15
> **说明:**
>
16 17
> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口为系统接口,三方应用不支持调用。
Z
zengyawen 已提交
18

Z
zengyawen 已提交
19 20

## 导入模块
Z
zengyawen 已提交
21

22
```js
Z
zengyawen 已提交
23 24 25 26
import deviceManager from '@ohos.distributedHardware.deviceManager';
```


Z
zengyawen 已提交
27 28 29
## deviceManager.createDeviceManager

createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void
Z
zengyawen 已提交
30 31

创建一个设备管理器实例。
32 33 34

**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
35
**参数:**
@
@shi-xiaoxiao-iris 已提交
36

37 38 39 40
| 参数名     | 类型                                                 | 必填 | 说明                                                        |
| ---------- | ---------------------------------------------------- | ---- | ----------------------------------------------------------- |
| bundleName | string                                               | 是   | 指示应用程序的Bundle名称。                                  |
| callback   | AsyncCallback<[DeviceManager](#devicemanager)> | 是   | DeviceManager实例创建时调用的回调,返回设备管理器对象实例。 |
Z
zengyawen 已提交
41

@
@shi-xiaoxiao-iris 已提交
42
**错误码:**
@
@shi-xiaoxiao-iris 已提交
43

@
@shi-xiaoxiao-iris 已提交
44
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
45

@
@shi-xiaoxiao-iris 已提交
46
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
47 48 49
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600102 | Failed to obtain the service.                                   |
@
@shi-xiaoxiao-iris 已提交
50

@
@shi-xiaoxiao-iris 已提交
51
**示例:**
@
@shi-xiaoxiao-iris 已提交
52

53 54 55
  ```js
  try {
    deviceManager.createDeviceManager("ohos.samples.jshelloworld", (err, data) => {
Z
zengyawen 已提交
56
      if (err) { 
57
        console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
58
        return;
Z
zengyawen 已提交
59 60
      }
      console.info("createDeviceManager success");
H
HelloCrease 已提交
61
      let dmInstance = data;
62 63
    });
  } catch(err) {
64
    console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
65
  }
Z
zengyawen 已提交
66 67
  ```

68
## DeviceInfo
Z
zengyawen 已提交
69

70
设备信息。
Z
zengyawen 已提交
71

72 73
**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
74
| 名称                     | 类型                        | 必填   | 说明       |
H
HelloCrease 已提交
75 76 77 78 79
| ---------------------- | ------------------------- | ---- | -------- |
| deviceId               | string                    | 是    | 设备的唯一标识。 |
| deviceName             | string                    | 是    | 设备名称。    |
| deviceType             | [DeviceType](#devicetype) | 是    | 设备类型。    |
| networkId<sup>8+</sup> | string                    | 是    | 设备网络标识。  |
S
summer8999 已提交
80
| range<sup>9+</sup>     | number                    | 是    | 发现设备的距离。  |
W
wangxuanxuan 已提交
81
| authForm<sup>10+</sup> | [AuthForm](#authform)     | 是    | 设备认证类型  |
Z
zengyawen 已提交
82 83

## DeviceType
Z
zengyawen 已提交
84 85 86

表示设备类型的枚举类。

87 88
**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
89
| 名称           | 值  | 说明   |
H
HelloCrease 已提交
90 91 92 93 94 95 96 97
| ------------ | ---- | ---- |
| SPEAKER      | 0x0A | 智能音箱 |
| PHONE        | 0x0E | 手机   |
| TABLET       | 0x11 | 平板   |
| WEARABLE     | 0x6D | 智能穿戴 |
| TV           | 0x9C | 智慧屏  |
| CAR          | 0x83 | 车    |
| UNKNOWN_TYPE | 0    | 未知设备 |
98

W
wangxuanxuan 已提交
99 100 101 102 103 104 105 106 107 108 109 110
## AuthForm

表示设备认证类型的枚举类。

**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

| 名称                 | 值  | 说明             |
| ------------------- | ---- | --------------- |
| INVALID_TYPE        | -1   | 设备没有认证 |
| PEER_TO_PEER        | 0    | 无账号设备点对点认证   |
| IDENTICAL_ACCOUNT   | 1    | 设备同账号认证   |
| ACROSS_ACCOUNT      | 2    | 设备跨账号认证 |
Z
zengyawen 已提交
111

112
## DeviceStateChangeAction
Z
zengyawen 已提交
113

114 115 116 117
表示设备状态变化的枚举。

**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
118
| 名称      | 值  | 说明              |
H
HelloCrease 已提交
119
| ------- | ---- | --------------- |
S
summer8999 已提交
120 121 122
| ONLINE  | 0    | 设备物理上线状态。           |
| READY   | 1    | 设备可用状态,表示设备间信息已在分布式数据中同步完成, 可以运行分布式业务。 |
| OFFLINE | 2    | 设备物理下线状态。           |
H
HelloCrease 已提交
123
| CHANGE  | 3    | 设备信息更改。         |
124 125 126 127

## SubscribeInfo

发现信息。
Z
zengyawen 已提交
128

129 130
**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
131
| 名称            | 类型                                | 必填   | 说明                |
H
HelloCrease 已提交
132 133 134 135 136
| ------------- | --------------------------------- | ---- | ----------------- |
| subscribeId   | number                            | 是    | 发现标识,用于标识不同的发现周期。 |
| mode          | [DiscoverMode ](#discovermode)    | 否    | 发现模式。             |
| medium        | [ExchangeMedium](#exchangemedium) | 否    | 发现类型。             |
| freq          | [ExchangeFreq](#exchangefreq)     | 否    | 发现频率。             |
137
| isSameAccount | boolean                           | 否    | 是否同帐号。            |
H
HelloCrease 已提交
138 139
| isWakeRemote  | boolean                           | 否    | 是否唤醒设备。           |
| capability    | [SubscribeCap](#subscribecap)     | 否    | 发现能力。             |
140 141 142 143 144 145 146 147


## DiscoverMode 

表示发现模式的枚举。

**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
148
| 名称                    | 值  | 说明    |
H
HelloCrease 已提交
149
| --------------------- | ---- | ----- |
150
| DISCOVER_MODE_PASSIVE | 0x55 | 被动模式。 |
H
HelloCrease 已提交
151
| DISCOVER_MODE_ACTIVE  | 0xAA | 主动模式。 |
152 153 154 155 156 157 158 159


## ExchangeMedium 

表示发现类型的枚举。

**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
160
| 名称   | 值  | 说明        |
H
HelloCrease 已提交
161 162 163 164 165
| ---- | ---- | --------- |
| AUTO | 0    | 自动发现类型。   |
| BLE  | 1    | 蓝牙发现类型。   |
| COAP | 2    | WiFi发现类型。 |
| USB  | 3    | USB发现类型。  |
166 167 168 169 170 171 172

## ExchangeFreq 

表示发现频率的枚举。

**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
173
| 名称         | 值  | 说明    |
H
HelloCrease 已提交
174 175 176 177 178
| ---------- | ---- | ----- |
| LOW        | 0    | 低频率。  |
| MID        | 1    | 中频率。  |
| HIGH       | 2    | 高频率。  |
| SUPER_HIGH | 3    | 超高频率。 |
179 180 181 182 183 184 185 186


## SubscribeCap 

表示发现能力的枚举。

**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
187
| 名称                        | 值  | 说明             |
H
HelloCrease 已提交
188 189 190
| ------------------------- | ---- | -------------- |
| SUBSCRIBE_CAPABILITY_DDMP | 0    | DDMP能力,后续会被废弃。 |
| SUBSCRIBE_CAPABILITY_OSD  | 1    | OSD能力。         |
191 192 193 194 195 196 197 198


## AuthParam

认证参数。

**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
199
| 名称        | 类型                   | 必填   | 说明         |
H
HelloCrease 已提交
200 201
| --------- | -------------------- | ---- | ---------- |
| authType  | number               | 是    | 认证类型。      |
202
| extraInfo | {[key:string]&nbsp;:&nbsp;any} | 否    | 认证参数可扩展字段。 |
203 204 205 206 207 208 209

## AuthInfo

认证信息。

**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
210
| 名称        | 类型                   | 必填   | 说明         |
H
HelloCrease 已提交
211 212 213
| --------- | -------------------- | ---- | ---------- |
| authType  | number               | 是    | 认证类型。      |
| token     | number               | 是    | 认证Token。   |
214
| extraInfo | {[key:string]&nbsp;:&nbsp;any} | 否    | 认证信息可扩展字段。 |
Z
zengyawen 已提交
215

@
@shi-xiaoxiao-iris 已提交
216
## PublishInfo<sup>9+</sup>
S
summer8999 已提交
217 218 219 220 221

发布设备参数

**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
222
| 名称          | 类型                              | 必填   | 说明                |
S
summer8999 已提交
223 224 225 226 227
| ------------- | --------------------------------- | ---- | ----------------- |
| publishId     | number                            | 是    | 发布设备标识,用于标识不同的发布周期。 |
| mode          | [DiscoverMode ](#discovermode)    | 是    | 发现模式。             |
| freq          | [ExchangeFreq](#exchangefreq)     | 是    | 发现频率。             |
| ranging       | boolean                           | 是    | 发布的设备是否支持测距能力。             |
Z
zengyawen 已提交
228 229

## DeviceManager
Z
zengyawen 已提交
230 231 232

设备管理实例,用于获取可信设备和本地设备的相关信息。在调用DeviceManager的方法前,需要先通过createDeviceManager构建一个DeviceManager实例dmInstance。

Z
zengyawen 已提交
233
### release
Z
zengyawen 已提交
234

Z
zengyawen 已提交
235
release(): void
Z
zengyawen 已提交
236

Z
zengyawen 已提交
237
设备管理实例不再使用后,通过该方法释放DeviceManager实例。
Z
zengyawen 已提交
238

239 240
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
241
**错误码:**
@
@shi-xiaoxiao-iris 已提交
242

@
@shi-xiaoxiao-iris 已提交
243
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
244

@
@shi-xiaoxiao-iris 已提交
245
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
246 247
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
248

@
@shi-xiaoxiao-iris 已提交
249
**示例:**
@
@shi-xiaoxiao-iris 已提交
250

251
  ```js
252 253 254
  try {
    dmInstance.release();
  } catch (err) {
255
    console.error("release errCode:" + err.code + ",errMessage:" + err.message);
256
  }
Z
zengyawen 已提交
257
  ```
Z
zengyawen 已提交
258

Z
zengyawen 已提交
259
### getTrustedDeviceListSync
Z
zengyawen 已提交
260

Z
zengyawen 已提交
261
getTrustedDeviceListSync(): Array&lt;DeviceInfo&gt;
Z
zengyawen 已提交
262 263 264

同步获取所有可信设备列表。

265 266
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

267 268
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
269
**返回值:**
@
@shi-xiaoxiao-iris 已提交
270

H
HelloCrease 已提交
271 272
  | 名称                                     | 说明        |
  | -------------------------------------- | --------- |
Z
zengyawen 已提交
273 274
  | Array&lt;[DeviceInfo](#deviceinfo)&gt; | 返回可信设备列表。 |

@
@shi-xiaoxiao-iris 已提交
275
**错误码:**
@
@shi-xiaoxiao-iris 已提交
276

@
@shi-xiaoxiao-iris 已提交
277
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
278

@
@shi-xiaoxiao-iris 已提交
279
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
280 281
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
282

@
@shi-xiaoxiao-iris 已提交
283
**示例:**
@
@shi-xiaoxiao-iris 已提交
284

285
  ```js
286 287 288
  try {
    var deviceInfoList = dmInstance.getTrustedDeviceListSync();
  } catch (err) {
289
    console.error("getTrustedDeviceListSync errCode:" + err.code + ",errMessage:" + err.message);
290
  }
Z
zengyawen 已提交
291
  ```
Z
zengyawen 已提交
292

293 294 295 296 297 298
### getTrustedDeviceList<sup>8+</sup>

getTrustedDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceInfo&gt;&gt;): void

获取所有可信设备列表。使用callback异步回调。

299 300
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

301 302
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
303
**参数:**
@
@shi-xiaoxiao-iris 已提交
304

@
@shi-xiaoxiao-iris 已提交
305
  | 参数名       | 类型                                     | 必填   | 说明                    |
H
HelloCrease 已提交
306 307
  | -------- | ---------------------------------------- | ---- | --------------------- |
  | callback | AsyncCallback&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | 是    | 获取所有可信设备列表的回调,返回设备信息。 |
308

@
@shi-xiaoxiao-iris 已提交
309
**错误码:**
@
@shi-xiaoxiao-iris 已提交
310

@
@shi-xiaoxiao-iris 已提交
311
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
312

@
@shi-xiaoxiao-iris 已提交
313
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
314 315
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
316

@
@shi-xiaoxiao-iris 已提交
317
**示例:**
@
@shi-xiaoxiao-iris 已提交
318

319
  ```js
320 321 322
  try {
    dmInstance.getTrustedDeviceList((err, data) => {
      if (err) {
323
        console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
324 325
        return;
      }
326
      console.log('get trusted device info: ' + JSON.stringify(data));
327
    });
328
  } catch (err) {
329
    console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
330
  }
331 332 333 334 335 336 337 338
  ```

### getTrustedDeviceList<sup>8+</sup>

getTrustedDeviceList(): Promise&lt;Array&lt;DeviceInfo&gt;&gt;

获取所有可信设备列表。使用Promise异步回调。

339 340
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

341 342
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
343
**返回值:**
@
@shi-xiaoxiao-iris 已提交
344

H
HelloCrease 已提交
345 346
  | 类型                                       | 说明                    |
  | ---------------------------------------- | --------------------- |
347 348
  | Promise&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | Promise实例,用于获取异步返回结果。 |

@
@shi-xiaoxiao-iris 已提交
349
**错误码:**
@
@shi-xiaoxiao-iris 已提交
350

@
@shi-xiaoxiao-iris 已提交
351
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
352

@
@shi-xiaoxiao-iris 已提交
353
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
354 355
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
356

@
@shi-xiaoxiao-iris 已提交
357
**示例:**
@
@shi-xiaoxiao-iris 已提交
358

359
  ```js
360 361 362
  dmInstance.getTrustedDeviceList().then((data) => {
    console.log('get trusted device info: ' + JSON.stringify(data));
    }).catch((err) => {
363
      console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
364
  });
365 366 367 368 369 370 371 372
  ```

### getLocalDeviceInfoSync<sup>8+</sup>

getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo)

同步获取本地设备信息。

373 374
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

375 376
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
377
**返回值:**
@
@shi-xiaoxiao-iris 已提交
378

379 380 381
  | 名称                      | 说明              |
  | ------------------------- | ---------------- |
  | [DeviceInfo](#deviceinfo) | 返回本地设备列表。 |
382

@
@shi-xiaoxiao-iris 已提交
383
**错误码:**
@
@shi-xiaoxiao-iris 已提交
384

@
@shi-xiaoxiao-iris 已提交
385
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
386

@
@shi-xiaoxiao-iris 已提交
387
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
388 389
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
390

@
@shi-xiaoxiao-iris 已提交
391
**示例:**
@
@shi-xiaoxiao-iris 已提交
392

393
  ```js
394 395 396
  try {
    var deviceInfo = dmInstance.getLocalDeviceInfoSync();
  } catch (err) {
397
    console.error("getLocalDeviceInfoSync errCode:" + err.code + ",errMessage:" + err.message);
398
  }
399 400 401 402 403 404 405 406
  ```

### getLocalDeviceInfo<sup>8+</sup>

getLocalDeviceInfo(callback:AsyncCallback&lt;DeviceInfo&gt;): void

获取本地设备信息。使用callback异步回调。

407 408
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

409 410
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
411
**参数:**
@
@shi-xiaoxiao-iris 已提交
412

@
@shi-xiaoxiao-iris 已提交
413
  | 参数名       | 类型                                     | 必填   | 说明        |
H
HelloCrease 已提交
414 415
  | -------- | ---------------------------------------- | ---- | --------- |
  | callback | AsyncCallback&lt;[DeviceInfo](#deviceinfo)&gt; | 是    | 获取本地设备信息。 |
416

@
@shi-xiaoxiao-iris 已提交
417
**错误码:**
@
@shi-xiaoxiao-iris 已提交
418

@
@shi-xiaoxiao-iris 已提交
419
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
420

@
@shi-xiaoxiao-iris 已提交
421
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
422 423
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
424

@
@shi-xiaoxiao-iris 已提交
425
**示例:**
@
@shi-xiaoxiao-iris 已提交
426

427
  ```js
428
  try {
429
    dmInstance.getLocalDeviceInfo((err, data) => {
430
    if (err) {
431
      console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
432
      return;
433
    }
434 435 436
      console.log('get local device info: ' + JSON.stringify(data));
    });
  } catch (err) {
437
    console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
438
  }
439 440 441 442 443 444 445 446
  ```

### getLocalDeviceInfo<sup>8+</sup>

getLocalDeviceInfo(): Promise&lt;DeviceInfo&gt;

获取本地设备信息。使用Promise异步回调。

447 448
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

449 450
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
451 452
**返回值:**

H
HelloCrease 已提交
453 454
  | 类型                                       | 说明                    |
  | ---------------------------------------- | --------------------- |
455 456
  | Promise&lt;[DeviceInfo](#deviceinfo)&gt; | Promise实例,用于获取异步返回结果。 |

@
@shi-xiaoxiao-iris 已提交
457
**错误码:**
@
@shi-xiaoxiao-iris 已提交
458

@
@shi-xiaoxiao-iris 已提交
459
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
460

@
@shi-xiaoxiao-iris 已提交
461
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
462 463 464
| ------- | --------------------------------------------------------------- |
| 11600101| Failed to execute the function.                                 |

@
@shi-xiaoxiao-iris 已提交
465
**示例:**
@
@shi-xiaoxiao-iris 已提交
466

467
  ```js
468 469 470
  dmInstance.getLocalDeviceInfo().then((data) => {
    console.log('get local device info: ' + JSON.stringify(data));
  }).catch((err) => {
471
    console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
472
  });
473 474
  ```

@
@shi-xiaoxiao-iris 已提交
475
### startDeviceDiscovery<sup>8+</sup>
476 477 478 479 480

startDeviceDiscovery(subscribeInfo: SubscribeInfo): void

发现周边设备。

481 482
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

483 484
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
485
**参数:**
@
@shi-xiaoxiao-iris 已提交
486

@
@shi-xiaoxiao-iris 已提交
487
  | 参数名            | 类型                       | 必填 | 说明    |
H
HelloCrease 已提交
488
  | ------------- | ------------------------------- | ---- | ----- |
489
  | subscribeInfo | [SubscribeInfo](#subscribeinfo) | 是   | 发现信息。|
490

@
@shi-xiaoxiao-iris 已提交
491
**错误码:**
@
@shi-xiaoxiao-iris 已提交
492

@
@shi-xiaoxiao-iris 已提交
493
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
494

@
@shi-xiaoxiao-iris 已提交
495
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
496 497 498 499
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600104 | Discovery invalid.                                              |

@
@shi-xiaoxiao-iris 已提交
500
**示例:**
@
@shi-xiaoxiao-iris 已提交
501

502
  ```js
503
  // 生成发现标识,随机数确保每次调用发现接口的标识不一致
504 505 506
  var subscribeId = Math.floor(Math.random() * 10000 + 1000);
  var subscribeInfo = {
      "subscribeId": subscribeId,
507 508 509
      "mode": 0xAA, // 主动模式
      "medium": 0,  // 自动发现类型,同时支持多种发现类型
      "freq": 2,    // 高频率
510 511 512 513
      "isSameAccount": false,
      "isWakeRemote": false,
      "capability": 1
  };
514 515 516
  try {
    dmInstance.startDeviceDiscovery(subscribeInfo); // 当有设备发现时,通过deviceFound回调通知给应用程序
  } catch (err) {
517
    console.error("startDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
518
  }
519 520
  ```

@
@shi-xiaoxiao-iris 已提交
521
### startDeviceDiscovery<sup>9+</sup>
S
summer8999 已提交
522

S
summer8999 已提交
523
startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void
S
summer8999 已提交
524 525 526

发现周边设备。

527 528
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

S
summer8999 已提交
529 530
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
531
**参数:**
@
@shi-xiaoxiao-iris 已提交
532

@
@shi-xiaoxiao-iris 已提交
533
  | 参数名            | 类型                       | 必填   | 说明    |
534
  | ------------- | ------------------------------- | ---- | -----  |
S
summer8999 已提交
535
  | subscribeInfo | [SubscribeInfo](#subscribeinfo) | 是   | 发现信息。 |
536
  | filterOptions | string                          | 否   | 发现设备过滤信息。|
S
summer8999 已提交
537

@
@shi-xiaoxiao-iris 已提交
538
**错误码:**
@
@shi-xiaoxiao-iris 已提交
539

@
@shi-xiaoxiao-iris 已提交
540
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
541

@
@shi-xiaoxiao-iris 已提交
542
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
543 544 545 546
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600104 | Discovery invalid.                                              |

@
@shi-xiaoxiao-iris 已提交
547
**示例:**
@
@shi-xiaoxiao-iris 已提交
548

S
summer8999 已提交
549
  ```js
550
  // 生成发现标识,随机数确保每次调用发现接口的标识不一致
S
summer8999 已提交
551 552 553
  var subscribeId = Math.floor(Math.random() * 10000 + 1000);
  var subscribeInfo = {
      "subscribeId": subscribeId,
554 555 556
      "mode": 0xAA, // 主动模式
      "medium": 0,  // 自动发现类型,同时支持多种发现类型
      "freq": 2,    // 高频率
S
summer8999 已提交
557 558 559 560 561
      "isSameAccount": false,
      "isWakeRemote": false,
      "capability": 1
  };
  var filterOptions = {
S
summer8999 已提交
562
    "filter_op": "OR", // 可选, 默认"OR"
S
summer8999 已提交
563 564 565
    "filters": [
        {
            "type": "range",
S
summer8999 已提交
566
            "value": 50 // 需过滤发现设备的距离,单位(cm)
S
summer8999 已提交
567 568
        }
    ]
S
summer8999 已提交
569
  };
570 571 572
  try {
    dmInstance.startDeviceDiscovery(subscribeInfo, JSON.stringify(filterOptions)); // 当有设备发现时,通过deviceFound回调通知给应用程序
  } catch (err) {
573
    console.error("startDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
574
  }
S
summer8999 已提交
575
  ```
@
@shi-xiaoxiao-iris 已提交
576

577 578 579 580 581 582
### stopDeviceDiscovery

stopDeviceDiscovery(subscribeId: number): void

停止发现周边设备。

583 584
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

585 586
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
587
**参数:**
@
@shi-xiaoxiao-iris 已提交
588

@
@shi-xiaoxiao-iris 已提交
589
  | 参数名          | 类型   | 必填   | 说明    |
H
HelloCrease 已提交
590 591
  | ----------- | ------ | ---- | ----- |
  | subscribeId | number | 是    | 发现标识。 |
592

@
@shi-xiaoxiao-iris 已提交
593
**错误码:**
@
@shi-xiaoxiao-iris 已提交
594

@
@shi-xiaoxiao-iris 已提交
595
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
596

@
@shi-xiaoxiao-iris 已提交
597
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
598 599
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
600

@
@shi-xiaoxiao-iris 已提交
601
**示例:**
@
@shi-xiaoxiao-iris 已提交
602

603
  ```js
604
  try {
605 606
    // stopDeviceDiscovery和startDeviceDiscovery需配对使用,入参需要和startDeviceDiscovery接口传入的subscribeId值相等
    var subscribeId = 12345;
607 608
    dmInstance.stopDeviceDiscovery(subscribeId);
  } catch (err) {
609
    console.error("stopDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
610
  }
611 612
  ```

@
@shi-xiaoxiao-iris 已提交
613
### publishDeviceDiscovery<sup>9+</sup>
S
summer8999 已提交
614

S
summer8999 已提交
615
publishDeviceDiscovery(publishInfo: PublishInfo): void
S
summer8999 已提交
616

S
summer8999 已提交
617
发布设备发现。
S
summer8999 已提交
618

619 620
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

S
summer8999 已提交
621 622
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
623
**参数:**
@
@shi-xiaoxiao-iris 已提交
624

@
@shi-xiaoxiao-iris 已提交
625
  | 参数名          | 类型                        | 必填 | 说明    |
S
summer8999 已提交
626 627 628
  | ------------- | ------------------------------- | ---- | ----- |
  | publishInfo   | [PublishInfo](#publishinfo)     | 是   | 发布设备发现信息。 |

@
@shi-xiaoxiao-iris 已提交
629
**错误码:**
@
@shi-xiaoxiao-iris 已提交
630

@
@shi-xiaoxiao-iris 已提交
631
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
632

@
@shi-xiaoxiao-iris 已提交
633
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
634 635 636
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600105 | Publish invalid.                                                |
@
@shi-xiaoxiao-iris 已提交
637

@
@shi-xiaoxiao-iris 已提交
638
**示例:**
@
@shi-xiaoxiao-iris 已提交
639

S
summer8999 已提交
640
  ```js
641
  // 生成发布标识,随机数确保每次调用发布接口的标识不一致
S
summer8999 已提交
642
  var publishId = Math.floor(Math.random() * 10000 + 1000);
S
summer8999 已提交
643
  var publishInfo = {
S
summer8999 已提交
644
      "publishId": publishId,
645 646
      "mode": 0xAA, // 主动模式
      "freq": 2,    // 高频率
647
      "ranging": true  // 支持发现时测距
S
summer8999 已提交
648
  };
649 650 651
  try {
    dmInstance.publishDeviceDiscovery(publishInfo); // 当有发布结果时,通过回调通知给应用程序
  } catch (err) {
652
    console.error("publishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
653
  }
S
summer8999 已提交
654
  ```
655

@
@shi-xiaoxiao-iris 已提交
656
### unPublishDeviceDiscovery<sup>9+</sup>
S
summer8999 已提交
657

S
summer8999 已提交
658
unPublishDeviceDiscovery(publishId: number): void
S
summer8999 已提交
659 660 661

停止发布设备发现。

662 663
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

S
summer8999 已提交
664 665
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
666
**参数:**
@
@shi-xiaoxiao-iris 已提交
667

@
@shi-xiaoxiao-iris 已提交
668
  | 参数名        | 类型 | 必填 | 说明  |
S
summer8999 已提交
669 670
  | ----------- | -------- | ---- | ----- |
  | publishId   | number   | 是   | 发布标识。 |
S
summer8999 已提交
671

@
@shi-xiaoxiao-iris 已提交
672
**错误码:**
@
@shi-xiaoxiao-iris 已提交
673

@
@shi-xiaoxiao-iris 已提交
674
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
675

@
@shi-xiaoxiao-iris 已提交
676
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
677 678
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
679

@
@shi-xiaoxiao-iris 已提交
680
**示例:**
@
@shi-xiaoxiao-iris 已提交
681

S
summer8999 已提交
682
  ```js
683
  try {
684 685
    // unPublishDeviceDiscovery和publishDeviceDiscovery配对使用,入参需要和publishDeviceDiscovery接口传入的publishId值相等
    var publishId = 12345;
686
    dmInstance.unPublishDeviceDiscovery(publishId);
687
  } catch (err) {
688
    console.error("unPublishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
689
  }
S
summer8999 已提交
690 691
  ```

692 693
### authenticateDevice

694
authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback&lt;{deviceId: string, pinToken ?: number}&gt;): void
695 696 697

认证设备。

698 699
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

700 701
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
702
**参数:**
@
@shi-xiaoxiao-iris 已提交
703

@
@shi-xiaoxiao-iris 已提交
704
  | 参数名         | 类型                                     | 必填   | 说明      |
H
HelloCrease 已提交
705 706 707
  | ---------- | ---------------------------------------- | ---- | ------- |
  | deviceInfo | [DeviceInfo](#deviceinfo)                | 是    | 设备信息。   |
  | authParam  | [AuthParam](#authparam)                  | 是    | 认证参数。   |
708
  | callback   | AsyncCallback&lt;{deviceId:&nbsp;string,&nbsp;pinToken&nbsp;?:&nbsp;number}&gt; | 是    | 认证结果回调。 |
709

@
@shi-xiaoxiao-iris 已提交
710
**错误码:**
@
@shi-xiaoxiao-iris 已提交
711

@
@shi-xiaoxiao-iris 已提交
712
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
713

@
@shi-xiaoxiao-iris 已提交
714
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
715 716 717
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600103 | Authentication invalid.                                         |
@
@shi-xiaoxiao-iris 已提交
718

@
@shi-xiaoxiao-iris 已提交
719
**示例:**
@
@shi-xiaoxiao-iris 已提交
720

721
  ```js
722
  // 认证的设备信息,可以从发现的结果中获取
723 724 725
  var deviceInfo ={
      "deviceId": "XXXXXXXX",
      "deviceName": "",
726 727 728
      "deviceType": 0x0E,
      "networkId" : "xxxxxxx",
      "range" : 0
729
  };
730 731 732 733 734
  let extraInfo = {
          'targetPkgName': 'ohos.samples.xxx',
          'appName': 'xxx',
          'appDescription': 'xxx',
          'business': '0'
735
  }
736
  let authParam = {
737 738
      'authType': 1,// 认证类型: 1 - 无帐号PIN码认证
      'extraInfo': extraInfo
739
  }
740 741
  try {
    dmInstance.authenticateDevice(deviceInfo, authParam, (err, data) => {
742
      if (err) {
743
          console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
744 745
          return;
      }
@
@shi-xiaoxiao-iris 已提交
746 747
      console.info("authenticateDevice result:" + JSON.stringify(data));
      let token = data.pinToken;
748 749
    });
  } catch (err) {
750
    console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
751
  }
752 753 754 755 756 757 758 759
  ```

### unAuthenticateDevice<sup>8+</sup>

unAuthenticateDevice(deviceInfo: DeviceInfo): void

解除认证设备。

760 761
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

762 763
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
764
**参数:**
@
@shi-xiaoxiao-iris 已提交
765

@
@shi-xiaoxiao-iris 已提交
766
  | 参数名         | 类型                      | 必填   | 说明    |
H
HelloCrease 已提交
767 768
  | ---------- | ------------------------- | ---- | ----- |
  | deviceInfo | [DeviceInfo](#deviceinfo) | 是    | 设备信息。 |
769

@
@shi-xiaoxiao-iris 已提交
770
**错误码:**
@
@shi-xiaoxiao-iris 已提交
771

@
@shi-xiaoxiao-iris 已提交
772
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
773

@
@shi-xiaoxiao-iris 已提交
774
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
775 776
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
777

@
@shi-xiaoxiao-iris 已提交
778
**示例:**
@
@shi-xiaoxiao-iris 已提交
779

780
  ```js
781
  try {
782 783 784 785 786 787 788
    var deviceInfo ={
      "deviceId": "XXXXXXXX",
      "deviceName": "",
      "deviceType": 0x0E,
      "networkId" : "xxxxxxx",
      "range" : 0
    };
789 790
    dmInstance.unAuthenticateDevice(deviceInfo);
  } catch (err) {
791
    console.error("unAuthenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
792
  }
793 794 795 796
  ```

### verifyAuthInfo

797
verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback&lt;{deviceId: string, level: number}&gt;): void
798 799 800

验证认证信息。

801 802
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

803 804
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
805
**参数:**
@
@shi-xiaoxiao-iris 已提交
806

@
@shi-xiaoxiao-iris 已提交
807
  | 参数名       | 类型                                     | 必填   | 说明      |
H
HelloCrease 已提交
808 809
  | -------- | ---------------------------------------- | ---- | ------- |
  | authInfo | [AuthInfo](#authinfo)                    | 是    | 认证信息。   |
810
  | callback | AsyncCallback&lt;{deviceId:&nbsp;string,&nbsp;level:&nbsp;number}&gt; | 是    | 验证结果回调。 |
811

@
@shi-xiaoxiao-iris 已提交
812
**错误码:**
@
@shi-xiaoxiao-iris 已提交
813

@
@shi-xiaoxiao-iris 已提交
814
以下的错误码的详细介绍请参见[设备管理错误码](../errorcodes/errorcode-device-manager.md)
@
@shi-xiaoxiao-iris 已提交
815

@
@shi-xiaoxiao-iris 已提交
816
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
817 818
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
819

@
@shi-xiaoxiao-iris 已提交
820
**示例:**
@
@shi-xiaoxiao-iris 已提交
821

822 823 824
  ```js
  let authInfo = {
    "authType": 1,
825
    "token": 123456,
826 827
    "extraInfo": {}
  }
828 829
  try {
    dmInstance.verifyAuthInfo(authInfo, (err, data) => {
830
    if (err) {
831
        console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
832 833
        return;
    }
@
@shi-xiaoxiao-iris 已提交
834
    console.info("verifyAuthInfo result:" + JSON.stringify(data));
835 836
    });
  } catch (err) {
837
    console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
838
  }
839 840
  ```

@
@shi-xiaoxiao-iris 已提交
841
### setUserOperation<sup>9+</sup>
@
@shi-xiaoxiao-iris 已提交
842 843 844 845 846

setUserOperation(operateAction: number, params: string): void;

设置用户ui操作行为。

847 848
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

@
@shi-xiaoxiao-iris 已提交
849 850
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
851
**参数:**
@
@shi-xiaoxiao-iris 已提交
852

@
@shi-xiaoxiao-iris 已提交
853
  | 参数名       | 类型            | 必填  | 说明                |
854 855 856
  | ------------- | --------------- | ---- | ------------------- |
  | operateAction | number          | 是    | 用户操作动作。       |
  | params        | string          | 是    | 表示用户的输入参数。 |
@
@shi-xiaoxiao-iris 已提交
857

@
@shi-xiaoxiao-iris 已提交
858
**示例:**
@
@shi-xiaoxiao-iris 已提交
859 860

  ```js
@
@shi-xiaoxiao-iris 已提交
861 862 863 864 865 866 867 868 869 870
 try {
    /*
      operateAction = 0 - 允许授权
      operateAction = 1 - 取消授权
      operateAction = 2 - 授权框用户操作超时
      operateAction = 3 - 取消pin码框展示
      operateAction = 4 - 取消pin码输入框展示
      operateAction = 5 - pin码输入框确定操作
    */
    let operation = 0;
871
    dmInstance.setUserOperation(operation, "extra")
@
@shi-xiaoxiao-iris 已提交
872 873
    } catch (err) {
      console.error("setUserOperation errCode:" + err.code + ",errMessage:" + err.message);
@
@shi-xiaoxiao-iris 已提交
874 875 876
  }
  ```

@
@shi-xiaoxiao-iris 已提交
877
### on('uiStateChange')<sup>9+</sup>
@
@shi-xiaoxiao-iris 已提交
878

879
on(type: 'uiStateChange', callback: Callback&lt;{ param: string}&gt;): void;
@
@shi-xiaoxiao-iris 已提交
880 881 882

ui状态变更回调。

883 884
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

@
@shi-xiaoxiao-iris 已提交
885 886
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
887
**参数:**
@
@shi-xiaoxiao-iris 已提交
888

@
@shi-xiaoxiao-iris 已提交
889
  | 参数名      | 类型                             | 必填 | 说明                            |
@
@shi-xiaoxiao-iris 已提交
890 891
  | -------- | ------------------------------------ | ---- | ------------------------------ |
  | type     | string                                | 是  | 注册的设备管理器 ui 状态回调,以便在状态改变时通知应用。 |
892
  | callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | 是  | 指示要注册的设备管理器 ui 状态回调,返回ui状态。        |
@
@shi-xiaoxiao-iris 已提交
893

@
@shi-xiaoxiao-iris 已提交
894
**示例:**
@
@shi-xiaoxiao-iris 已提交
895 896 897

  ```js
  try {
@
@shi-xiaoxiao-iris 已提交
898
    dmInstance.on('uiStateChange', (data) => {
@
@shi-xiaoxiao-iris 已提交
899 900
    console.log("uiStateChange executed, dialog closed" + JSON.stringify(data))
    var tmpStr = JSON.parse(data.param)
901 902
    var isShow = tmpStr.verifyFailed
    console.log("uiStateChange executed, dialog closed" + isShow)
@
@shi-xiaoxiao-iris 已提交
903 904 905 906 907 908
  });
  } catch (err) {
    console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

@
@shi-xiaoxiao-iris 已提交
909
### off('uiStateChange')<sup>9+</sup>
@
@shi-xiaoxiao-iris 已提交
910

911
off(type: 'uiStateChange', callback?: Callback&lt;{ param: string}&gt;): void;
@
@shi-xiaoxiao-iris 已提交
912

913 914 915
取消ui状态变更回调。

**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。
@
@shi-xiaoxiao-iris 已提交
916 917 918

**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
919
**参数:**
@
@shi-xiaoxiao-iris 已提交
920

@
@shi-xiaoxiao-iris 已提交
921
  | 参数名      | 类型                              | 必填 | 说明                            |
@
@shi-xiaoxiao-iris 已提交
922 923
  | -------- | ------------------------------------- | ---- | ------------------------------ |
  | type     | string                                | 是   | 取消注册的设备管理器 ui 状态回调。 |
924
  | callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | 否   | 指示要取消注册的设备管理器 ui 状态,返回UI状态。 |
@
@shi-xiaoxiao-iris 已提交
925

@
@shi-xiaoxiao-iris 已提交
926
**示例:**
@
@shi-xiaoxiao-iris 已提交
927 928 929

  ```js
  try {
@
@shi-xiaoxiao-iris 已提交
930
    dmInstance.off('uiStateChange');
@
@shi-xiaoxiao-iris 已提交
931 932 933 934 935
  } catch (err) {
    console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

Z
zengyawen 已提交
936
### on('deviceStateChange')
Z
zengyawen 已提交
937

938
on(type: 'deviceStateChange',  callback: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void
Z
zengyawen 已提交
939

Z
zengyawen 已提交
940 941
注册设备状态回调。

942 943
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

944 945
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
946
**参数:**
@
@shi-xiaoxiao-iris 已提交
947

@
@shi-xiaoxiao-iris 已提交
948
  | 参数名       | 类型                                     | 必填   | 说明                             |
H
HelloCrease 已提交
949 950
  | -------- | ---------------------------------------- | ---- | ------------------------------ |
  | type     | string                                   | 是    | 注册设备状态回调,固定为deviceStateChange。 |
951
  | callback | Callback&lt;{&nbsp;action:&nbsp;[DeviceStateChangeAction](#devicestatechangeaction),&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | 是    | 指示要注册的设备状态回调,返回设备状态和设备信息。      |
Z
zengyawen 已提交
952

@
@shi-xiaoxiao-iris 已提交
953
**示例:**
@
@shi-xiaoxiao-iris 已提交
954

955
  ```js
956 957 958 959 960
  try {
    dmInstance.on('deviceStateChange', (data) => {
      console.info("deviceStateChange on:" + JSON.stringify(data));
    });
  } catch (err) {
961
    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
962
  }
Z
zengyawen 已提交
963
  ```
Z
zengyawen 已提交
964

Z
zengyawen 已提交
965
### off('deviceStateChange')
Z
zengyawen 已提交
966

967
off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void
Z
zengyawen 已提交
968 969 970

取消注册设备状态回调。

971 972
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

973 974
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
975
**参数:**
@
@shi-xiaoxiao-iris 已提交
976

@
@shi-xiaoxiao-iris 已提交
977
  | 参数名       | 类型                                     | 必填   | 说明                          |
H
HelloCrease 已提交
978 979
  | -------- | ---------------------------------------- | ---- | --------------------------- |
  | type     | string                                   | 是    | 根据应用程序的包名取消注册设备状态回调。        |
980
  | callback | Callback&lt;{&nbsp;action:&nbsp;[DeviceStateChangeAction](#devicestatechangeaction),&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | 否    | 指示要取消注册的设备状态回调,返回设备状态和设备信息。 |
Z
zengyawen 已提交
981

@
@shi-xiaoxiao-iris 已提交
982
**示例:**
@
@shi-xiaoxiao-iris 已提交
983

984
  ```js
985 986 987 988 989
  try {
    dmInstance.off('deviceStateChange', (data) => {
      console.info('deviceStateChange' + JSON.stringify(data));
    });
  } catch (err) {
990
    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
991
  }
Z
zengyawen 已提交
992 993
  ```

994 995
### on('deviceFound')

996
on(type: 'deviceFound', callback: Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt;): void
997 998 999

注册发现设备回调监听。

1000 1001
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

1002 1003
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1004
**参数:**
@
@shi-xiaoxiao-iris 已提交
1005

@
@shi-xiaoxiao-iris 已提交
1006
  | 参数名       | 类型                                     | 必填   | 说明                         |
H
HelloCrease 已提交
1007 1008
  | -------- | ---------------------------------------- | ---- | -------------------------- |
  | type     | string                                   | 是    | 注册设备发现回调,以便在发现周边设备时通知应用程序。 |
1009
  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | 是    | 注册设备发现的回调方法。               |
1010

@
@shi-xiaoxiao-iris 已提交
1011
**示例:**
@
@shi-xiaoxiao-iris 已提交
1012

1013
  ```js
1014 1015 1016 1017 1018
  try {
    dmInstance.on('deviceFound', (data) => {
      console.info("deviceFound:" + JSON.stringify(data));
    });
  } catch (err) {
1019
    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
1020
  }
1021 1022 1023 1024
  ```

### off('deviceFound')

1025
off(type: 'deviceFound', callback?: Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt;): void
1026 1027 1028

取消注册设备发现回调。

1029 1030
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

1031 1032
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1033
**参数:**
@
@shi-xiaoxiao-iris 已提交
1034

@
@shi-xiaoxiao-iris 已提交
1035
  | 参数名       | 类型                                     | 必填   | 说明                          |
H
HelloCrease 已提交
1036 1037
  | -------- | ---------------------------------------- | ---- | --------------------------- |
  | type     | string                                   | 是    | 取消注册设备发现回调。                 |
1038
  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | 否    | 指示要取消注册的设备发现回调,返回设备状态和设备信息。 |
1039

@
@shi-xiaoxiao-iris 已提交
1040
**示例:**
@
@shi-xiaoxiao-iris 已提交
1041

1042
  ```js
1043 1044 1045 1046 1047
  try {
    dmInstance.off('deviceFound', (data) => {
      console.info('deviceFound' + JSON.stringify(data));
    });
  } catch (err) {
1048
    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
1049
  }
1050 1051 1052 1053
  ```

### on('discoverFail')

1054
on(type: 'discoverFail', callback: Callback&lt;{ subscribeId: number, reason: number }&gt;): void
1055 1056 1057

注册设备发现失败回调监听。

1058 1059
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

1060 1061
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1062
**参数:**
@
@shi-xiaoxiao-iris 已提交
1063

@
@shi-xiaoxiao-iris 已提交
1064
  | 参数名       | 类型                                     | 必填   | 说明                             |
H
HelloCrease 已提交
1065 1066
  | -------- | ---------------------------------------- | ---- | ------------------------------ |
  | type     | string                                   | 是    | 注册设备发现失败回调,以便在发现周边设备失败时通知应用程序。 |
1067
  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | 是    | 注册设备发现失败的回调方法。                 |
1068

@
@shi-xiaoxiao-iris 已提交
1069
**示例:**
@
@shi-xiaoxiao-iris 已提交
1070

1071
  ```js
1072 1073
  try {
    dmInstance.on('discoverFail', (data) => {
1074
        console.info("discoverFail on:" + JSON.stringify(data));
1075
    });
1076
  } catch (err) {
1077
    console.error("discoverFail errCode:" + err.code + ",errMessage:" + err.message);
1078
  }
1079 1080 1081 1082
  ```

### off('discoverFail')

1083
off(type: 'discoverFail', callback?: Callback&lt;{ subscribeId: number, reason: number }&gt;): void
1084 1085 1086

取消注册设备发现失败回调。

1087 1088
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

1089 1090
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1091
**参数:**
@
@shi-xiaoxiao-iris 已提交
1092

@
@shi-xiaoxiao-iris 已提交
1093
  | 参数名       | 类型                                     | 必填   | 说明                |
H
HelloCrease 已提交
1094 1095
  | -------- | ---------------------------------------- | ---- | ----------------- |
  | type     | string                                   | 是    | 取消注册设备发现失败回调。     |
1096
  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | 否    | 指示要取消注册的设备发现失败回调。 |
1097

@
@shi-xiaoxiao-iris 已提交
1098
**示例:**
@
@shi-xiaoxiao-iris 已提交
1099

1100
  ```js
1101 1102 1103 1104 1105
  try {
    dmInstance.off('discoverFail', (data) => {
      console.info('discoverFail' + JSON.stringify(data));
    });
  } catch (err) {
1106
    console.error("discoverFail errCode:" + err.code + ",errMessage:" + err.message);
1107
  }
1108 1109
  ```

@
@shi-xiaoxiao-iris 已提交
1110
### on('publishSuccess')<sup>9+</sup>
S
summer8999 已提交
1111

1112
on(type: 'publishSuccess', callback: Callback&lt;{ publishId: number }&gt;): void
S
summer8999 已提交
1113 1114 1115

注册发布设备发现回调监听。

1116 1117
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

S
summer8999 已提交
1118 1119
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1120
**参数:**
@
@shi-xiaoxiao-iris 已提交
1121

@
@shi-xiaoxiao-iris 已提交
1122
  | 参数名     | 类型                                 | 必填 | 说明                       |
S
summer8999 已提交
1123
  | -------- | ---------------------------------------- | ---- | -------------------------- |
S
summer8999 已提交
1124
  | type     | string                                   | 是   | 注册发布设备成功回调,以便将发布成功时通知应用程序。 |
1125
  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number&nbsp;}&gt;    | 是   | 注册设备发布成功的回调方法。               |
S
summer8999 已提交
1126

@
@shi-xiaoxiao-iris 已提交
1127

@
@shi-xiaoxiao-iris 已提交
1128
**示例:**
@
@shi-xiaoxiao-iris 已提交
1129

S
summer8999 已提交
1130
  ```js
1131 1132 1133 1134 1135
  try {
    dmInstance.on('publishSuccess', (data) => {
      console.info("publishSuccess:" + JSON.stringify(data));
    });
  } catch (err) {
1136
    console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message);
1137
  }
S
summer8999 已提交
1138 1139
  ```

@
@shi-xiaoxiao-iris 已提交
1140
### off('publishSuccess')<sup>9+</sup>
S
summer8999 已提交
1141

1142
off(type: 'publishSuccess', callback?: Callback&lt;{ publishId: number }&gt;): void
S
summer8999 已提交
1143

S
summer8999 已提交
1144
取消注册设备发布成功回调。
S
summer8999 已提交
1145

1146 1147
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

S
summer8999 已提交
1148 1149
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1150
**参数:**
@
@shi-xiaoxiao-iris 已提交
1151

@
@shi-xiaoxiao-iris 已提交
1152
  | 参数名     | 类型                                 | 必填 | 说明                          |
S
summer8999 已提交
1153
  | -------- | ---------------------------------------- | ---- | --------------------------- |
S
summer8999 已提交
1154
  | type     | string                                   | 是   | 取消注册设备发布成功回调。                 |
1155
  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number&nbsp;}&gt;    | 否   | 指示要取消注册的设备发布成功回调。 |
S
summer8999 已提交
1156

@
@shi-xiaoxiao-iris 已提交
1157
**示例:**
@
@shi-xiaoxiao-iris 已提交
1158

S
summer8999 已提交
1159
  ```js
1160 1161 1162 1163 1164
  try {
    dmInstance.off('publishSuccess', (data) => {
      console.info('publishSuccess' + JSON.stringify(data));
    });
  } catch (err) {
1165
    console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message);
1166
  }
S
summer8999 已提交
1167 1168
  ```

@
@shi-xiaoxiao-iris 已提交
1169
### on('publishFail')<sup>9+</sup>
S
summer8999 已提交
1170

1171
on(type: 'publishFail', callback: Callback&lt;{ publishId: number, reason: number }&gt;): void
S
summer8999 已提交
1172 1173 1174

注册设备发布失败回调监听。

1175 1176
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

S
summer8999 已提交
1177 1178
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1179
**参数:**
@
@shi-xiaoxiao-iris 已提交
1180

@
@shi-xiaoxiao-iris 已提交
1181
  | 参数名     | 类型                                              | 必填 | 说明                             |
S
summer8999 已提交
1182 1183
  | -------- | ----------------------------------------------------- | ---- | ------------------------------ |
  | type     | string                                                | 是   | 注册设备发布失败回调,以便在发布设备失败时通知应用程序。 |
1184
  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | 是   | 注册设备发布失败的回调方法。                 |
S
summer8999 已提交
1185

@
@shi-xiaoxiao-iris 已提交
1186
**示例:**
@
@shi-xiaoxiao-iris 已提交
1187

S
summer8999 已提交
1188
  ```js
1189 1190
  try {
    dmInstance.on('publishFail', (data) => {
1191
      console.info("publishFail on:" + JSON.stringify(data));
1192 1193
    });
  } catch (err) {
1194
    console.error("publishFail errCode:" + err.code + ",errMessage:" + err.message);
1195
  }
S
summer8999 已提交
1196 1197
  ```

@
@shi-xiaoxiao-iris 已提交
1198
### off('publishFail')<sup>9+</sup>
S
summer8999 已提交
1199

1200
off(type: 'publishFail', callback?: Callback&lt;{ publishId: number, reason: number }&gt;): void
S
summer8999 已提交
1201

S
summer8999 已提交
1202
取消注册设备发布失败回调。
S
summer8999 已提交
1203

1204 1205
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

S
summer8999 已提交
1206 1207
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1208
**参数:**
@
@shi-xiaoxiao-iris 已提交
1209

@
@shi-xiaoxiao-iris 已提交
1210
  | 参数名     | 类型                                              | 必填 | 说明                |
S
summer8999 已提交
1211 1212
  | -------- | ----------------------------------------------------- | ---- | ----------------- |
  | type     | string                                                | 是   | 取消注册设备发布失败回调。     |
1213
  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | 否   | 指示要取消注册设备发布失败回调。 |
S
summer8999 已提交
1214

@
@shi-xiaoxiao-iris 已提交
1215
**示例:**
@
@shi-xiaoxiao-iris 已提交
1216

S
summer8999 已提交
1217
  ```js
1218 1219 1220 1221 1222
  try {
    dmInstance.off('publishFail', (data) => {
      console.info('publishFail' + JSON.stringify(data));
    });
  } catch (err) {
1223
    console.error("publishFail errCode:" + err.code + ",errMessage:" + err.message);
1224
  }
S
summer8999 已提交
1225
  ```
1226

Z
zengyawen 已提交
1227 1228 1229
### on('serviceDie')

on(type: 'serviceDie', callback: () =&gt; void): void
Z
zengyawen 已提交
1230 1231 1232

注册设备管理服务死亡监听。

1233 1234
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

1235 1236
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1237
**参数:**
@
@shi-xiaoxiao-iris 已提交
1238

@
@shi-xiaoxiao-iris 已提交
1239
  | 参数名       | 类型                    | 必填   | 说明                                       |
H
HelloCrease 已提交
1240 1241 1242
  | -------- | ----------------------- | ---- | ---------------------------------------- |
  | type     | string                  | 是    | 注册serviceDie回调,以便在devicemanager服务异常终止时通知应用程序。 |
  | callback | ()&nbsp;=&gt;&nbsp;void | 是    | 注册serviceDie的回调方法。                       |
Z
zengyawen 已提交
1243

@
@shi-xiaoxiao-iris 已提交
1244
**示例:**
@
@shi-xiaoxiao-iris 已提交
1245

1246
  ```js
1247 1248 1249 1250 1251
  try {
    dmInstance.on("serviceDie", () => {
      console.info("serviceDie on");
    });
  } catch (err) {
1252
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1253
  }
Z
zengyawen 已提交
1254
  ```
Z
zengyawen 已提交
1255

Z
zengyawen 已提交
1256 1257 1258 1259 1260
### off('serviceDie')

off(type: 'serviceDie', callback?: () =&gt; void): void

取消注册设备管理服务死亡监听。
Z
zengyawen 已提交
1261

1262 1263
**需要权限**:ohos.permission.ACCESS_SERVICE_DM,仅系统应用可用。

1264 1265
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1266
**参数:**
@
@shi-xiaoxiao-iris 已提交
1267

@
@shi-xiaoxiao-iris 已提交
1268
  | 参数名       | 类型                    | 必填   | 说明                                       |
H
HelloCrease 已提交
1269 1270 1271
  | -------- | ----------------------- | ---- | ---------------------------------------- |
  | type     | string                  | 是    | 取消注册serviceDie回调,以便在devicemanager服务异常终止时通知应用程序。 |
  | callback | ()&nbsp;=&gt;&nbsp;void | 否    | 取消注册serviceDie的回调方法。                     |
Z
zengyawen 已提交
1272

@
@shi-xiaoxiao-iris 已提交
1273
**示例:**
@
@shi-xiaoxiao-iris 已提交
1274

1275
  ```js
1276 1277 1278 1279 1280
  try {
    dmInstance.off("serviceDie", () => {
      console.info("serviceDie off");
    });
  } catch (err) {
1281
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1282
  }
1283
  ```