js-apis-device-manager.md 45.1 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                    | 是    | 发现设备的距离。  |
Z
zengyawen 已提交
81 82

## DeviceType
Z
zengyawen 已提交
83 84 85

表示设备类型的枚举类。

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

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

Z
zengyawen 已提交
98

99
## DeviceStateChangeAction
Z
zengyawen 已提交
100

101 102 103 104
表示设备状态变化的枚举。

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

@
@shi-xiaoxiao-iris 已提交
105
| 名称      | 值  | 说明              |
H
HelloCrease 已提交
106
| ------- | ---- | --------------- |
S
summer8999 已提交
107 108 109
| ONLINE  | 0    | 设备物理上线状态。           |
| READY   | 1    | 设备可用状态,表示设备间信息已在分布式数据中同步完成, 可以运行分布式业务。 |
| OFFLINE | 2    | 设备物理下线状态。           |
H
HelloCrease 已提交
110
| CHANGE  | 3    | 设备信息更改。         |
111 112 113 114

## SubscribeInfo

发现信息。
Z
zengyawen 已提交
115

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

@
@shi-xiaoxiao-iris 已提交
118
| 名称            | 类型                                | 必填   | 说明                |
H
HelloCrease 已提交
119 120 121 122 123
| ------------- | --------------------------------- | ---- | ----------------- |
| subscribeId   | number                            | 是    | 发现标识,用于标识不同的发现周期。 |
| mode          | [DiscoverMode ](#discovermode)    | 否    | 发现模式。             |
| medium        | [ExchangeMedium](#exchangemedium) | 否    | 发现类型。             |
| freq          | [ExchangeFreq](#exchangefreq)     | 否    | 发现频率。             |
124
| isSameAccount | boolean                           | 否    | 是否同帐号。            |
H
HelloCrease 已提交
125 126
| isWakeRemote  | boolean                           | 否    | 是否唤醒设备。           |
| capability    | [SubscribeCap](#subscribecap)     | 否    | 发现能力。             |
127 128 129 130 131 132 133 134


## DiscoverMode 

表示发现模式的枚举。

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

@
@shi-xiaoxiao-iris 已提交
135
| 名称                    | 值  | 说明    |
H
HelloCrease 已提交
136
| --------------------- | ---- | ----- |
137
| DISCOVER_MODE_PASSIVE | 0x55 | 被动模式。 |
H
HelloCrease 已提交
138
| DISCOVER_MODE_ACTIVE  | 0xAA | 主动模式。 |
139 140 141 142 143 144 145 146


## ExchangeMedium 

表示发现类型的枚举。

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

@
@shi-xiaoxiao-iris 已提交
147
| 名称   | 值  | 说明        |
H
HelloCrease 已提交
148 149 150 151 152
| ---- | ---- | --------- |
| AUTO | 0    | 自动发现类型。   |
| BLE  | 1    | 蓝牙发现类型。   |
| COAP | 2    | WiFi发现类型。 |
| USB  | 3    | USB发现类型。  |
153 154 155 156 157 158 159

## ExchangeFreq 

表示发现频率的枚举。

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

@
@shi-xiaoxiao-iris 已提交
160
| 名称         | 值  | 说明    |
H
HelloCrease 已提交
161 162 163 164 165
| ---------- | ---- | ----- |
| LOW        | 0    | 低频率。  |
| MID        | 1    | 中频率。  |
| HIGH       | 2    | 高频率。  |
| SUPER_HIGH | 3    | 超高频率。 |
166 167 168 169 170 171 172 173


## SubscribeCap 

表示发现能力的枚举。

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

@
@shi-xiaoxiao-iris 已提交
174
| 名称                        | 值  | 说明             |
H
HelloCrease 已提交
175 176 177
| ------------------------- | ---- | -------------- |
| SUBSCRIBE_CAPABILITY_DDMP | 0    | DDMP能力,后续会被废弃。 |
| SUBSCRIBE_CAPABILITY_OSD  | 1    | OSD能力。         |
178 179 180 181 182 183 184 185


## AuthParam

认证参数。

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

@
@shi-xiaoxiao-iris 已提交
186
| 名称        | 类型                   | 必填   | 说明         |
H
HelloCrease 已提交
187 188
| --------- | -------------------- | ---- | ---------- |
| authType  | number               | 是    | 认证类型。      |
189
| extraInfo | {[key:string]&nbsp;:&nbsp;any} | 否    | 认证参数可扩展字段。 |
190 191 192 193 194 195 196

## AuthInfo

认证信息。

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

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

@
@shi-xiaoxiao-iris 已提交
203
## PublishInfo<sup>9+</sup>
S
summer8999 已提交
204 205 206 207 208

发布设备参数

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

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

## DeviceManager
Z
zengyawen 已提交
217 218 219

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

Z
zengyawen 已提交
220
### release
Z
zengyawen 已提交
221

Z
zengyawen 已提交
222
release(): void
Z
zengyawen 已提交
223

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

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

@
@shi-xiaoxiao-iris 已提交
228
**错误码:**
@
@shi-xiaoxiao-iris 已提交
229

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

@
@shi-xiaoxiao-iris 已提交
232
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
233 234
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
235

@
@shi-xiaoxiao-iris 已提交
236
**示例:**
@
@shi-xiaoxiao-iris 已提交
237

238
  ```js
239 240 241
  try {
    dmInstance.release();
  } catch (err) {
242
    console.error("release errCode:" + err.code + ",errMessage:" + err.message);
243
  }
Z
zengyawen 已提交
244
  ```
Z
zengyawen 已提交
245

Z
zengyawen 已提交
246
### getTrustedDeviceListSync
Z
zengyawen 已提交
247

Z
zengyawen 已提交
248
getTrustedDeviceListSync(): Array&lt;DeviceInfo&gt;
Z
zengyawen 已提交
249 250 251

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

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

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

@
@shi-xiaoxiao-iris 已提交
256
**返回值:**
@
@shi-xiaoxiao-iris 已提交
257

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

@
@shi-xiaoxiao-iris 已提交
262
**错误码:**
@
@shi-xiaoxiao-iris 已提交
263

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

@
@shi-xiaoxiao-iris 已提交
266
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
267 268
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
269

@
@shi-xiaoxiao-iris 已提交
270
**示例:**
@
@shi-xiaoxiao-iris 已提交
271

272
  ```js
273 274 275
  try {
    var deviceInfoList = dmInstance.getTrustedDeviceListSync();
  } catch (err) {
276
    console.error("getTrustedDeviceListSync errCode:" + err.code + ",errMessage:" + err.message);
277
  }
Z
zengyawen 已提交
278
  ```
Z
zengyawen 已提交
279

280 281 282 283 284 285
### getTrustedDeviceList<sup>8+</sup>

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
290
**参数:**
@
@shi-xiaoxiao-iris 已提交
291

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

@
@shi-xiaoxiao-iris 已提交
296
**错误码:**
@
@shi-xiaoxiao-iris 已提交
297

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

@
@shi-xiaoxiao-iris 已提交
300
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
301 302
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
303

@
@shi-xiaoxiao-iris 已提交
304
**示例:**
@
@shi-xiaoxiao-iris 已提交
305

306
  ```js
307 308 309
  try {
    dmInstance.getTrustedDeviceList((err, data) => {
      if (err) {
310
        console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
311 312
        return;
      }
313
      console.log('get trusted device info: ' + JSON.stringify(data));
314
    });
315
  } catch (err) {
316
    console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
317
  }
318 319 320 321 322 323 324 325
  ```

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
330
**返回值:**
@
@shi-xiaoxiao-iris 已提交
331

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

@
@shi-xiaoxiao-iris 已提交
336
**错误码:**
@
@shi-xiaoxiao-iris 已提交
337

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

@
@shi-xiaoxiao-iris 已提交
340
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
341 342
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
343

@
@shi-xiaoxiao-iris 已提交
344
**示例:**
@
@shi-xiaoxiao-iris 已提交
345

346
  ```js
347 348 349
  dmInstance.getTrustedDeviceList().then((data) => {
    console.log('get trusted device info: ' + JSON.stringify(data));
    }).catch((err) => {
350
      console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
351
  });
352 353 354 355 356 357 358 359
  ```

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

getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo)

同步获取本地设备信息。

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

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

@
@shi-xiaoxiao-iris 已提交
364
**返回值:**
@
@shi-xiaoxiao-iris 已提交
365

366 367 368
  | 名称                      | 说明              |
  | ------------------------- | ---------------- |
  | [DeviceInfo](#deviceinfo) | 返回本地设备列表。 |
369

@
@shi-xiaoxiao-iris 已提交
370
**错误码:**
@
@shi-xiaoxiao-iris 已提交
371

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

@
@shi-xiaoxiao-iris 已提交
374
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
375 376
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
377

@
@shi-xiaoxiao-iris 已提交
378
**示例:**
@
@shi-xiaoxiao-iris 已提交
379

380
  ```js
381 382 383
  try {
    var deviceInfo = dmInstance.getLocalDeviceInfoSync();
  } catch (err) {
384
    console.error("getLocalDeviceInfoSync errCode:" + err.code + ",errMessage:" + err.message);
385
  }
386 387 388 389 390 391 392 393
  ```

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
398
**参数:**
@
@shi-xiaoxiao-iris 已提交
399

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

@
@shi-xiaoxiao-iris 已提交
404
**错误码:**
@
@shi-xiaoxiao-iris 已提交
405

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

@
@shi-xiaoxiao-iris 已提交
408
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
409 410
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
411

@
@shi-xiaoxiao-iris 已提交
412
**示例:**
@
@shi-xiaoxiao-iris 已提交
413

414
  ```js
415
  try {
416
    dmInstance.getLocalDeviceInfo((err, data) => {
417
    if (err) {
418
      console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
419
      return;
420
    }
421 422 423
      console.log('get local device info: ' + JSON.stringify(data));
    });
  } catch (err) {
424
    console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
425
  }
426 427 428 429 430 431 432 433
  ```

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
438 439
**返回值:**

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

@
@shi-xiaoxiao-iris 已提交
444
**错误码:**
@
@shi-xiaoxiao-iris 已提交
445

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

@
@shi-xiaoxiao-iris 已提交
448
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
449 450 451
| ------- | --------------------------------------------------------------- |
| 11600101| Failed to execute the function.                                 |

@
@shi-xiaoxiao-iris 已提交
452
**示例:**
@
@shi-xiaoxiao-iris 已提交
453

454
  ```js
455 456 457
  dmInstance.getLocalDeviceInfo().then((data) => {
    console.log('get local device info: ' + JSON.stringify(data));
  }).catch((err) => {
458
    console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
459
  });
460 461
  ```

@
@shi-xiaoxiao-iris 已提交
462
### startDeviceDiscovery<sup>8+</sup>
463 464 465 466 467

startDeviceDiscovery(subscribeInfo: SubscribeInfo): void

发现周边设备。

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

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

@
@shi-xiaoxiao-iris 已提交
472
**参数:**
@
@shi-xiaoxiao-iris 已提交
473

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

@
@shi-xiaoxiao-iris 已提交
478
**错误码:**
@
@shi-xiaoxiao-iris 已提交
479

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

@
@shi-xiaoxiao-iris 已提交
482
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
483 484 485 486
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600104 | Discovery invalid.                                              |

@
@shi-xiaoxiao-iris 已提交
487
**示例:**
@
@shi-xiaoxiao-iris 已提交
488

489
  ```js
490
  // 生成发现标识,随机数确保每次调用发现接口的标识不一致
491 492 493
  var subscribeId = Math.floor(Math.random() * 10000 + 1000);
  var subscribeInfo = {
      "subscribeId": subscribeId,
494 495 496
      "mode": 0xAA, // 主动模式
      "medium": 0,  // 自动发现类型,同时支持多种发现类型
      "freq": 2,    // 高频率
497 498 499 500
      "isSameAccount": false,
      "isWakeRemote": false,
      "capability": 1
  };
501 502 503
  try {
    dmInstance.startDeviceDiscovery(subscribeInfo); // 当有设备发现时,通过deviceFound回调通知给应用程序
  } catch (err) {
504
    console.error("startDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
505
  }
506 507
  ```

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

S
summer8999 已提交
510
startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void
S
summer8999 已提交
511 512 513

发现周边设备。

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

S
summer8999 已提交
516 517
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
518
**参数:**
@
@shi-xiaoxiao-iris 已提交
519

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

@
@shi-xiaoxiao-iris 已提交
525
**错误码:**
@
@shi-xiaoxiao-iris 已提交
526

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

@
@shi-xiaoxiao-iris 已提交
529
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
530 531 532 533
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600104 | Discovery invalid.                                              |

@
@shi-xiaoxiao-iris 已提交
534
**示例:**
@
@shi-xiaoxiao-iris 已提交
535

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

564 565 566 567 568 569
### stopDeviceDiscovery

stopDeviceDiscovery(subscribeId: number): void

停止发现周边设备。

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

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

@
@shi-xiaoxiao-iris 已提交
574
**参数:**
@
@shi-xiaoxiao-iris 已提交
575

@
@shi-xiaoxiao-iris 已提交
576
  | 参数名          | 类型   | 必填   | 说明    |
H
HelloCrease 已提交
577 578
  | ----------- | ------ | ---- | ----- |
  | subscribeId | number | 是    | 发现标识。 |
579

@
@shi-xiaoxiao-iris 已提交
580
**错误码:**
@
@shi-xiaoxiao-iris 已提交
581

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

@
@shi-xiaoxiao-iris 已提交
584
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
585 586
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
587

@
@shi-xiaoxiao-iris 已提交
588
**示例:**
@
@shi-xiaoxiao-iris 已提交
589

590
  ```js
591
  try {
592 593
    // stopDeviceDiscovery和startDeviceDiscovery需配对使用,入参需要和startDeviceDiscovery接口传入的subscribeId值相等
    var subscribeId = 12345;
594 595
    dmInstance.stopDeviceDiscovery(subscribeId);
  } catch (err) {
596
    console.error("stopDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
597
  }
598 599
  ```

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

S
summer8999 已提交
602
publishDeviceDiscovery(publishInfo: PublishInfo): void
S
summer8999 已提交
603

S
summer8999 已提交
604
发布设备发现。
S
summer8999 已提交
605

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

S
summer8999 已提交
608 609
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
610
**参数:**
@
@shi-xiaoxiao-iris 已提交
611

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

@
@shi-xiaoxiao-iris 已提交
616
**错误码:**
@
@shi-xiaoxiao-iris 已提交
617

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

@
@shi-xiaoxiao-iris 已提交
620
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
621 622 623
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600105 | Publish invalid.                                                |
@
@shi-xiaoxiao-iris 已提交
624

@
@shi-xiaoxiao-iris 已提交
625
**示例:**
@
@shi-xiaoxiao-iris 已提交
626

S
summer8999 已提交
627
  ```js
628
  // 生成发布标识,随机数确保每次调用发布接口的标识不一致
S
summer8999 已提交
629
  var publishId = Math.floor(Math.random() * 10000 + 1000);
S
summer8999 已提交
630
  var publishInfo = {
S
summer8999 已提交
631
      "publishId": publishId,
632 633
      "mode": 0xAA, // 主动模式
      "freq": 2,    // 高频率
634
      "ranging": true  // 支持发现时测距
S
summer8999 已提交
635
  };
636 637 638
  try {
    dmInstance.publishDeviceDiscovery(publishInfo); // 当有发布结果时,通过回调通知给应用程序
  } catch (err) {
639
    console.error("publishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
640
  }
S
summer8999 已提交
641
  ```
642

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

S
summer8999 已提交
645
unPublishDeviceDiscovery(publishId: number): void
S
summer8999 已提交
646 647 648

停止发布设备发现。

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

S
summer8999 已提交
651 652
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
653
**参数:**
@
@shi-xiaoxiao-iris 已提交
654

@
@shi-xiaoxiao-iris 已提交
655
  | 参数名        | 类型 | 必填 | 说明  |
S
summer8999 已提交
656 657
  | ----------- | -------- | ---- | ----- |
  | publishId   | number   | 是   | 发布标识。 |
S
summer8999 已提交
658

@
@shi-xiaoxiao-iris 已提交
659
**错误码:**
@
@shi-xiaoxiao-iris 已提交
660

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

@
@shi-xiaoxiao-iris 已提交
663
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
664 665
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
666

@
@shi-xiaoxiao-iris 已提交
667
**示例:**
@
@shi-xiaoxiao-iris 已提交
668

S
summer8999 已提交
669
  ```js
670
  try {
671 672
    // unPublishDeviceDiscovery和publishDeviceDiscovery配对使用,入参需要和publishDeviceDiscovery接口传入的publishId值相等
    var publishId = 12345;
673
    dmInstance.unPublishDeviceDiscovery(publishId);
674
  } catch (err) {
675
    console.error("unPublishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
676
  }
S
summer8999 已提交
677 678
  ```

679 680
### authenticateDevice

681
authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback&lt;{deviceId: string, pinToken ?: number}&gt;): void
682 683 684

认证设备。

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

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

@
@shi-xiaoxiao-iris 已提交
689
**参数:**
@
@shi-xiaoxiao-iris 已提交
690

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

@
@shi-xiaoxiao-iris 已提交
697
**错误码:**
@
@shi-xiaoxiao-iris 已提交
698

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

@
@shi-xiaoxiao-iris 已提交
701
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
702 703 704
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600103 | Authentication invalid.                                         |
@
@shi-xiaoxiao-iris 已提交
705

@
@shi-xiaoxiao-iris 已提交
706
**示例:**
@
@shi-xiaoxiao-iris 已提交
707

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

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

unAuthenticateDevice(deviceInfo: DeviceInfo): void

解除认证设备。

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

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

@
@shi-xiaoxiao-iris 已提交
751
**参数:**
@
@shi-xiaoxiao-iris 已提交
752

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

@
@shi-xiaoxiao-iris 已提交
757
**错误码:**
@
@shi-xiaoxiao-iris 已提交
758

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

@
@shi-xiaoxiao-iris 已提交
761
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
762 763
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
764

@
@shi-xiaoxiao-iris 已提交
765
**示例:**
@
@shi-xiaoxiao-iris 已提交
766

767
  ```js
768
  try {
769 770 771 772 773 774 775
    var deviceInfo ={
      "deviceId": "XXXXXXXX",
      "deviceName": "",
      "deviceType": 0x0E,
      "networkId" : "xxxxxxx",
      "range" : 0
    };
776 777
    dmInstance.unAuthenticateDevice(deviceInfo);
  } catch (err) {
778
    console.error("unAuthenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
779
  }
780 781 782 783
  ```

### verifyAuthInfo

784
verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback&lt;{deviceId: string, level: number}&gt;): void
785 786 787

验证认证信息。

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

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

@
@shi-xiaoxiao-iris 已提交
792
**参数:**
@
@shi-xiaoxiao-iris 已提交
793

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

@
@shi-xiaoxiao-iris 已提交
799
**错误码:**
@
@shi-xiaoxiao-iris 已提交
800

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

@
@shi-xiaoxiao-iris 已提交
803
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
804 805
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
806

@
@shi-xiaoxiao-iris 已提交
807
**示例:**
@
@shi-xiaoxiao-iris 已提交
808

809 810 811
  ```js
  let authInfo = {
    "authType": 1,
812
    "token": 123456,
813 814
    "extraInfo": {}
  }
815 816
  try {
    dmInstance.verifyAuthInfo(authInfo, (err, data) => {
817
    if (err) {
818
        console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
819 820
        return;
    }
@
@shi-xiaoxiao-iris 已提交
821
    console.info("verifyAuthInfo result:" + JSON.stringify(data));
822 823
    });
  } catch (err) {
824
    console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
825
  }
826 827
  ```

@
@shi-xiaoxiao-iris 已提交
828
### setUserOperation<sup>9+</sup>
@
@shi-xiaoxiao-iris 已提交
829 830 831 832 833

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

设置用户ui操作行为。

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

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

@
@shi-xiaoxiao-iris 已提交
838
**参数:**
@
@shi-xiaoxiao-iris 已提交
839

@
@shi-xiaoxiao-iris 已提交
840
  | 参数名       | 类型            | 必填  | 说明                |
841 842 843
  | ------------- | --------------- | ---- | ------------------- |
  | operateAction | number          | 是    | 用户操作动作。       |
  | params        | string          | 是    | 表示用户的输入参数。 |
@
@shi-xiaoxiao-iris 已提交
844

@
@shi-xiaoxiao-iris 已提交
845
**示例:**
@
@shi-xiaoxiao-iris 已提交
846 847

  ```js
@
@shi-xiaoxiao-iris 已提交
848 849 850 851 852 853 854 855 856 857
 try {
    /*
      operateAction = 0 - 允许授权
      operateAction = 1 - 取消授权
      operateAction = 2 - 授权框用户操作超时
      operateAction = 3 - 取消pin码框展示
      operateAction = 4 - 取消pin码输入框展示
      operateAction = 5 - pin码输入框确定操作
    */
    let operation = 0;
858
    dmInstance.setUserOperation(operation, "extra")
@
@shi-xiaoxiao-iris 已提交
859 860
    } catch (err) {
      console.error("setUserOperation errCode:" + err.code + ",errMessage:" + err.message);
@
@shi-xiaoxiao-iris 已提交
861 862 863
  }
  ```

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

866
on(type: 'uiStateChange', callback: Callback&lt;{ param: string}&gt;): void;
@
@shi-xiaoxiao-iris 已提交
867 868 869

ui状态变更回调。

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

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

@
@shi-xiaoxiao-iris 已提交
874
**参数:**
@
@shi-xiaoxiao-iris 已提交
875

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

@
@shi-xiaoxiao-iris 已提交
881
**示例:**
@
@shi-xiaoxiao-iris 已提交
882 883 884

  ```js
  try {
@
@shi-xiaoxiao-iris 已提交
885
    dmInstance.on('uiStateChange', (data) => {
@
@shi-xiaoxiao-iris 已提交
886 887
    console.log("uiStateChange executed, dialog closed" + JSON.stringify(data))
    var tmpStr = JSON.parse(data.param)
888 889
    var isShow = tmpStr.verifyFailed
    console.log("uiStateChange executed, dialog closed" + isShow)
@
@shi-xiaoxiao-iris 已提交
890 891 892 893 894 895
  });
  } catch (err) {
    console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

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

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

900 901 902
取消ui状态变更回调。

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

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

@
@shi-xiaoxiao-iris 已提交
906
**参数:**
@
@shi-xiaoxiao-iris 已提交
907

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

@
@shi-xiaoxiao-iris 已提交
913
**示例:**
@
@shi-xiaoxiao-iris 已提交
914 915 916

  ```js
  try {
@
@shi-xiaoxiao-iris 已提交
917
    dmInstance.off('uiStateChange');
@
@shi-xiaoxiao-iris 已提交
918 919 920 921 922
  } catch (err) {
    console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

Z
zengyawen 已提交
923
### on('deviceStateChange')
Z
zengyawen 已提交
924

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

Z
zengyawen 已提交
927 928
注册设备状态回调。

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

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

@
@shi-xiaoxiao-iris 已提交
933
**参数:**
@
@shi-xiaoxiao-iris 已提交
934

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

@
@shi-xiaoxiao-iris 已提交
940
**示例:**
@
@shi-xiaoxiao-iris 已提交
941

942
  ```js
943 944 945 946 947
  try {
    dmInstance.on('deviceStateChange', (data) => {
      console.info("deviceStateChange on:" + JSON.stringify(data));
    });
  } catch (err) {
948
    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
949
  }
Z
zengyawen 已提交
950
  ```
Z
zengyawen 已提交
951

Z
zengyawen 已提交
952
### off('deviceStateChange')
Z
zengyawen 已提交
953

954
off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void
Z
zengyawen 已提交
955 956 957

取消注册设备状态回调。

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

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

@
@shi-xiaoxiao-iris 已提交
962
**参数:**
@
@shi-xiaoxiao-iris 已提交
963

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

@
@shi-xiaoxiao-iris 已提交
969
**示例:**
@
@shi-xiaoxiao-iris 已提交
970

971
  ```js
972 973 974 975 976
  try {
    dmInstance.off('deviceStateChange', (data) => {
      console.info('deviceStateChange' + JSON.stringify(data));
    });
  } catch (err) {
977
    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
978
  }
Z
zengyawen 已提交
979 980
  ```

981 982
### on('deviceFound')

983
on(type: 'deviceFound', callback: Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt;): void
984 985 986

注册发现设备回调监听。

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

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

@
@shi-xiaoxiao-iris 已提交
991
**参数:**
@
@shi-xiaoxiao-iris 已提交
992

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

@
@shi-xiaoxiao-iris 已提交
998
**示例:**
@
@shi-xiaoxiao-iris 已提交
999

1000
  ```js
1001 1002 1003 1004 1005
  try {
    dmInstance.on('deviceFound', (data) => {
      console.info("deviceFound:" + JSON.stringify(data));
    });
  } catch (err) {
1006
    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
1007
  }
1008 1009 1010 1011
  ```

### off('deviceFound')

1012
off(type: 'deviceFound', callback?: Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt;): void
1013 1014 1015

取消注册设备发现回调。

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

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

@
@shi-xiaoxiao-iris 已提交
1020
**参数:**
@
@shi-xiaoxiao-iris 已提交
1021

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

@
@shi-xiaoxiao-iris 已提交
1027
**示例:**
@
@shi-xiaoxiao-iris 已提交
1028

1029
  ```js
1030 1031 1032 1033 1034
  try {
    dmInstance.off('deviceFound', (data) => {
      console.info('deviceFound' + JSON.stringify(data));
    });
  } catch (err) {
1035
    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
1036
  }
1037 1038 1039 1040
  ```

### on('discoverFail')

1041
on(type: 'discoverFail', callback: Callback&lt;{ subscribeId: number, reason: number }&gt;): void
1042 1043 1044

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

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

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

@
@shi-xiaoxiao-iris 已提交
1049
**参数:**
@
@shi-xiaoxiao-iris 已提交
1050

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

@
@shi-xiaoxiao-iris 已提交
1056
**示例:**
@
@shi-xiaoxiao-iris 已提交
1057

1058
  ```js
1059 1060
  try {
    dmInstance.on('discoverFail', (data) => {
1061
        console.info("discoverFail on:" + JSON.stringify(data));
1062
    });
1063
  } catch (err) {
1064
    console.error("discoverFail errCode:" + err.code + ",errMessage:" + err.message);
1065
  }
1066 1067 1068 1069
  ```

### off('discoverFail')

1070
off(type: 'discoverFail', callback?: Callback&lt;{ subscribeId: number, reason: number }&gt;): void
1071 1072 1073

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

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

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

@
@shi-xiaoxiao-iris 已提交
1078
**参数:**
@
@shi-xiaoxiao-iris 已提交
1079

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

@
@shi-xiaoxiao-iris 已提交
1085
**示例:**
@
@shi-xiaoxiao-iris 已提交
1086

1087
  ```js
1088 1089 1090 1091 1092
  try {
    dmInstance.off('discoverFail', (data) => {
      console.info('discoverFail' + JSON.stringify(data));
    });
  } catch (err) {
1093
    console.error("discoverFail errCode:" + err.code + ",errMessage:" + err.message);
1094
  }
1095 1096
  ```

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

1099
on(type: 'publishSuccess', callback: Callback&lt;{ publishId: number }&gt;): void
S
summer8999 已提交
1100 1101 1102

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

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

S
summer8999 已提交
1105 1106
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1107
**参数:**
@
@shi-xiaoxiao-iris 已提交
1108

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

@
@shi-xiaoxiao-iris 已提交
1114

@
@shi-xiaoxiao-iris 已提交
1115
**示例:**
@
@shi-xiaoxiao-iris 已提交
1116

S
summer8999 已提交
1117
  ```js
1118 1119 1120 1121 1122
  try {
    dmInstance.on('publishSuccess', (data) => {
      console.info("publishSuccess:" + JSON.stringify(data));
    });
  } catch (err) {
1123
    console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message);
1124
  }
S
summer8999 已提交
1125 1126
  ```

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

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

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

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

S
summer8999 已提交
1135 1136
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1137
**参数:**
@
@shi-xiaoxiao-iris 已提交
1138

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

@
@shi-xiaoxiao-iris 已提交
1144
**示例:**
@
@shi-xiaoxiao-iris 已提交
1145

S
summer8999 已提交
1146
  ```js
1147 1148 1149 1150 1151
  try {
    dmInstance.off('publishSuccess', (data) => {
      console.info('publishSuccess' + JSON.stringify(data));
    });
  } catch (err) {
1152
    console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message);
1153
  }
S
summer8999 已提交
1154 1155
  ```

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

1158
on(type: 'publishFail', callback: Callback&lt;{ publishId: number, reason: number }&gt;): void
S
summer8999 已提交
1159 1160 1161

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

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

S
summer8999 已提交
1164 1165
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1166
**参数:**
@
@shi-xiaoxiao-iris 已提交
1167

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

@
@shi-xiaoxiao-iris 已提交
1173
**示例:**
@
@shi-xiaoxiao-iris 已提交
1174

S
summer8999 已提交
1175
  ```js
1176 1177
  try {
    dmInstance.on('publishFail', (data) => {
1178
      console.info("publishFail on:" + JSON.stringify(data));
1179 1180
    });
  } catch (err) {
1181
    console.error("publishFail errCode:" + err.code + ",errMessage:" + err.message);
1182
  }
S
summer8999 已提交
1183 1184
  ```

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

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

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

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

S
summer8999 已提交
1193 1194
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1195
**参数:**
@
@shi-xiaoxiao-iris 已提交
1196

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

@
@shi-xiaoxiao-iris 已提交
1202
**示例:**
@
@shi-xiaoxiao-iris 已提交
1203

S
summer8999 已提交
1204
  ```js
1205 1206 1207 1208 1209
  try {
    dmInstance.off('publishFail', (data) => {
      console.info('publishFail' + JSON.stringify(data));
    });
  } catch (err) {
1210
    console.error("publishFail errCode:" + err.code + ",errMessage:" + err.message);
1211
  }
S
summer8999 已提交
1212
  ```
1213

Z
zengyawen 已提交
1214 1215 1216
### on('serviceDie')

on(type: 'serviceDie', callback: () =&gt; void): void
Z
zengyawen 已提交
1217 1218 1219

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

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

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

@
@shi-xiaoxiao-iris 已提交
1224
**参数:**
@
@shi-xiaoxiao-iris 已提交
1225

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

@
@shi-xiaoxiao-iris 已提交
1231
**示例:**
@
@shi-xiaoxiao-iris 已提交
1232

1233
  ```js
1234 1235 1236 1237 1238
  try {
    dmInstance.on("serviceDie", () => {
      console.info("serviceDie on");
    });
  } catch (err) {
1239
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1240
  }
Z
zengyawen 已提交
1241
  ```
Z
zengyawen 已提交
1242

Z
zengyawen 已提交
1243 1244 1245 1246 1247
### off('serviceDie')

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
1253
**参数:**
@
@shi-xiaoxiao-iris 已提交
1254

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

@
@shi-xiaoxiao-iris 已提交
1260
**示例:**
@
@shi-xiaoxiao-iris 已提交
1261

1262
  ```js
1263 1264 1265 1266 1267
  try {
    dmInstance.off("serviceDie", () => {
      console.info("serviceDie off");
    });
  } catch (err) {
1268
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1269
  }
1270
  ```