js-apis-device-manager.md 42.1 KB
Newer Older
S
summer8999 已提交
1 2 3



Z
zengyawen 已提交
4
# 设备管理
Z
zengyawen 已提交
5

6 7 8 9 10 11 12 13 14
本模块提供分布式设备管理能力。

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

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

17 18
> **说明:**
>
19 20
> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口为系统接口,三方应用不支持调用。
21
> - 本模块系统接口调用需要申请权限:ohos.permission.ACCESS_SERVICE_DM。
Z
zengyawen 已提交
22

Z
zengyawen 已提交
23 24

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

26
```js
Z
zengyawen 已提交
27 28 29 30
import deviceManager from '@ohos.distributedHardware.deviceManager';
```


Z
zengyawen 已提交
31 32 33
## deviceManager.createDeviceManager

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

创建一个设备管理器实例。
36 37 38

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

@
@shi-xiaoxiao-iris 已提交
39
**参数:**
@
@shi-xiaoxiao-iris 已提交
40

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

@
@shi-xiaoxiao-iris 已提交
46
**错误码:**
@
@shi-xiaoxiao-iris 已提交
47

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

@
@shi-xiaoxiao-iris 已提交
50
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
51 52 53
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600102 | Failed to obtain the service.                                   |
@
@shi-xiaoxiao-iris 已提交
54

@
@shi-xiaoxiao-iris 已提交
55
**示例:**
@
@shi-xiaoxiao-iris 已提交
56

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

72
## DeviceInfo
Z
zengyawen 已提交
73

74
设备信息。
Z
zengyawen 已提交
75

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

H
HelloCrease 已提交
78 79 80 81 82 83
| 名称                     | 类型                        | 必填   | 描述       |
| ---------------------- | ------------------------- | ---- | -------- |
| deviceId               | string                    | 是    | 设备的唯一标识。 |
| deviceName             | string                    | 是    | 设备名称。    |
| deviceType             | [DeviceType](#devicetype) | 是    | 设备类型。    |
| networkId<sup>8+</sup> | string                    | 是    | 设备网络标识。  |
S
summer8999 已提交
84
| range<sup>9+</sup>     | number                    | 是    | 发现设备的距离。  |
Z
zengyawen 已提交
85 86

## DeviceType
Z
zengyawen 已提交
87 88 89

表示设备类型的枚举类。

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

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

Z
zengyawen 已提交
102

103
## DeviceStateChangeAction
Z
zengyawen 已提交
104

105 106 107 108
表示设备状态变化的枚举。

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

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

## SubscribeInfo

发现信息。
Z
zengyawen 已提交
119

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

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


## DiscoverMode 

表示发现模式的枚举。

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

H
HelloCrease 已提交
139 140
| 名称                    | 默认值  | 说明    |
| --------------------- | ---- | ----- |
141
| DISCOVER_MODE_PASSIVE | 0x55 | 被动模式。 |
H
HelloCrease 已提交
142
| DISCOVER_MODE_ACTIVE  | 0xAA | 主动模式。 |
143 144 145 146 147 148 149 150


## ExchangeMedium 

表示发现类型的枚举。

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

H
HelloCrease 已提交
151 152 153 154 155 156
| 名称   | 默认值  | 说明        |
| ---- | ---- | --------- |
| AUTO | 0    | 自动发现类型。   |
| BLE  | 1    | 蓝牙发现类型。   |
| COAP | 2    | WiFi发现类型。 |
| USB  | 3    | USB发现类型。  |
157 158 159 160 161 162 163

## ExchangeFreq 

表示发现频率的枚举。

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

H
HelloCrease 已提交
164 165 166 167 168 169
| 名称         | 默认值  | 说明    |
| ---------- | ---- | ----- |
| LOW        | 0    | 低频率。  |
| MID        | 1    | 中频率。  |
| HIGH       | 2    | 高频率。  |
| SUPER_HIGH | 3    | 超高频率。 |
170 171 172 173 174 175 176 177


## SubscribeCap 

表示发现能力的枚举。

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

H
HelloCrease 已提交
178 179 180 181
| 名称                        | 默认值  | 说明             |
| ------------------------- | ---- | -------------- |
| SUBSCRIBE_CAPABILITY_DDMP | 0    | DDMP能力,后续会被废弃。 |
| SUBSCRIBE_CAPABILITY_OSD  | 1    | OSD能力。         |
182 183 184 185 186 187 188 189


## AuthParam

认证参数。

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

H
HelloCrease 已提交
190 191 192 193
| 名称        | 类型                   | 必填   | 描述         |
| --------- | -------------------- | ---- | ---------- |
| authType  | number               | 是    | 认证类型。      |
| extraInfo | {[key:string] : any} | 否    | 认证参数可扩展字段。 |
194 195 196 197 198 199 200

## AuthInfo

认证信息。

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

H
HelloCrease 已提交
201 202 203 204 205
| 名称        | 类型                   | 必填   | 描述         |
| --------- | -------------------- | ---- | ---------- |
| authType  | number               | 是    | 认证类型。      |
| token     | number               | 是    | 认证Token。   |
| extraInfo | {[key:string] : any} | 否    | 认证信息可扩展字段。 |
Z
zengyawen 已提交
206

S
summer8999 已提交
207
## PublishInfo9+</sup>
S
summer8999 已提交
208 209 210 211 212 213 214 215 216 217 218

发布设备参数

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

| 名称          | 类型                              | 必填   | 描述                |
| ------------- | --------------------------------- | ---- | ----------------- |
| publishId     | number                            | 是    | 发布设备标识,用于标识不同的发布周期。 |
| mode          | [DiscoverMode ](#discovermode)    | 是    | 发现模式。             |
| freq          | [ExchangeFreq](#exchangefreq)     | 是    | 发现频率。             |
| ranging       | boolean                           | 是    | 发布的设备是否支持测距能力。             |
Z
zengyawen 已提交
219 220

## DeviceManager
Z
zengyawen 已提交
221 222 223

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

Z
zengyawen 已提交
224
### release
Z
zengyawen 已提交
225

Z
zengyawen 已提交
226
release(): void
Z
zengyawen 已提交
227

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

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

@
@shi-xiaoxiao-iris 已提交
232
**错误码:**
@
@shi-xiaoxiao-iris 已提交
233

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

@
@shi-xiaoxiao-iris 已提交
236
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
237 238
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
239

@
@shi-xiaoxiao-iris 已提交
240
**示例:**
@
@shi-xiaoxiao-iris 已提交
241

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

Z
zengyawen 已提交
250
### getTrustedDeviceListSync
Z
zengyawen 已提交
251

Z
zengyawen 已提交
252
getTrustedDeviceListSync(): Array&lt;DeviceInfo&gt;
Z
zengyawen 已提交
253 254 255

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

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

@
@shi-xiaoxiao-iris 已提交
258
**返回值:**
@
@shi-xiaoxiao-iris 已提交
259

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

@
@shi-xiaoxiao-iris 已提交
264
**错误码:**
@
@shi-xiaoxiao-iris 已提交
265

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

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

@
@shi-xiaoxiao-iris 已提交
272
**示例:**
@
@shi-xiaoxiao-iris 已提交
273

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

282 283 284 285 286 287 288 289
### getTrustedDeviceList<sup>8+</sup>

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

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

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

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

H
HelloCrease 已提交
292 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 326 327
  ```

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
328
**返回值:**
@
@shi-xiaoxiao-iris 已提交
329

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

@
@shi-xiaoxiao-iris 已提交
334
**错误码:**
@
@shi-xiaoxiao-iris 已提交
335

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

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

@
@shi-xiaoxiao-iris 已提交
342
**示例:**
@
@shi-xiaoxiao-iris 已提交
343

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

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

getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo)

同步获取本地设备信息。

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

@
@shi-xiaoxiao-iris 已提交
360
**返回值:**
@
@shi-xiaoxiao-iris 已提交
361

362 363 364
  | 名称                      | 说明              |
  | ------------------------- | ---------------- |
  | [DeviceInfo](#deviceinfo) | 返回本地设备列表。 |
365

@
@shi-xiaoxiao-iris 已提交
366
**错误码:**
@
@shi-xiaoxiao-iris 已提交
367

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

@
@shi-xiaoxiao-iris 已提交
370
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
371 372
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
373

@
@shi-xiaoxiao-iris 已提交
374
**示例:**
@
@shi-xiaoxiao-iris 已提交
375

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
392
**参数:**
@
@shi-xiaoxiao-iris 已提交
393

H
HelloCrease 已提交
394 395 396
  | 名称       | 参数类型                                     | 必填   | 说明        |
  | -------- | ---------------------------------------- | ---- | --------- |
  | callback | AsyncCallback&lt;[DeviceInfo](#deviceinfo)&gt; | 是    | 获取本地设备信息。 |
397

@
@shi-xiaoxiao-iris 已提交
398
**错误码:**
@
@shi-xiaoxiao-iris 已提交
399

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

@
@shi-xiaoxiao-iris 已提交
402
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
403 404
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
405

@
@shi-xiaoxiao-iris 已提交
406
**示例:**
@
@shi-xiaoxiao-iris 已提交
407

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
430 431
**返回值:**

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

@
@shi-xiaoxiao-iris 已提交
436
**错误码:**
@
@shi-xiaoxiao-iris 已提交
437

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

@
@shi-xiaoxiao-iris 已提交
440
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
441 442 443
| ------- | --------------------------------------------------------------- |
| 11600101| Failed to execute the function.                                 |

@
@shi-xiaoxiao-iris 已提交
444
**示例:**
@
@shi-xiaoxiao-iris 已提交
445

446
  ```js
447 448 449
  dmInstance.getLocalDeviceInfo().then((data) => {
    console.log('get local device info: ' + JSON.stringify(data));
  }).catch((err) => {
450
    console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
451
  });
452 453
  ```

S
summer8999 已提交
454
### startDeviceDiscovery8+</sup>
455 456 457 458 459 460 461

startDeviceDiscovery(subscribeInfo: SubscribeInfo): void

发现周边设备。

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

@
@shi-xiaoxiao-iris 已提交
462
**参数:**
@
@shi-xiaoxiao-iris 已提交
463

464
  | 名称            | 参数类型                       | 必填 | 说明    |
H
HelloCrease 已提交
465
  | ------------- | ------------------------------- | ---- | ----- |
466
  | subscribeInfo | [SubscribeInfo](#subscribeinfo) | 是   | 发现信息。|
467

@
@shi-xiaoxiao-iris 已提交
468
**错误码:**
@
@shi-xiaoxiao-iris 已提交
469

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

@
@shi-xiaoxiao-iris 已提交
472
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
473 474 475 476
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600104 | Discovery invalid.                                              |

@
@shi-xiaoxiao-iris 已提交
477
**示例:**
@
@shi-xiaoxiao-iris 已提交
478

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

S
summer8999 已提交
498 499
### startDeviceDiscovery9+</sup>

S
summer8999 已提交
500
startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void
S
summer8999 已提交
501 502 503 504 505

发现周边设备。

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

@
@shi-xiaoxiao-iris 已提交
506
**参数:**
@
@shi-xiaoxiao-iris 已提交
507

508 509
  | 名称            | 参数类型                       | 必填   | 说明    |
  | ------------- | ------------------------------- | ---- | -----  |
S
summer8999 已提交
510
  | subscribeInfo | [SubscribeInfo](#subscribeinfo) | 是   | 发现信息。 |
511
  | filterOptions | string                          | 否   | 发现设备过滤信息。|
S
summer8999 已提交
512

@
@shi-xiaoxiao-iris 已提交
513
**错误码:**
@
@shi-xiaoxiao-iris 已提交
514

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

@
@shi-xiaoxiao-iris 已提交
517
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
518 519 520 521
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600104 | Discovery invalid.                                              |

@
@shi-xiaoxiao-iris 已提交
522
**示例:**
@
@shi-xiaoxiao-iris 已提交
523

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

552 553 554 555 556 557 558 559
### stopDeviceDiscovery

stopDeviceDiscovery(subscribeId: number): void

停止发现周边设备。

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

@
@shi-xiaoxiao-iris 已提交
560
**参数:**
@
@shi-xiaoxiao-iris 已提交
561

H
HelloCrease 已提交
562 563 564
  | 名称          | 参数类型   | 必填   | 说明    |
  | ----------- | ------ | ---- | ----- |
  | subscribeId | number | 是    | 发现标识。 |
565

@
@shi-xiaoxiao-iris 已提交
566
**错误码:**
@
@shi-xiaoxiao-iris 已提交
567

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

@
@shi-xiaoxiao-iris 已提交
570
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
571 572
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
573

@
@shi-xiaoxiao-iris 已提交
574
**示例:**
@
@shi-xiaoxiao-iris 已提交
575

576
  ```js
577
  // 入参需要和startDeviceDiscovery接口传入的subscribeId配对使用
578 579 580
  try {
    dmInstance.stopDeviceDiscovery(subscribeId);
  } catch (err) {
581
    console.error("stopDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
582
  }
583 584
  ```

S
summer8999 已提交
585 586
### publishDeviceDiscovery9+</sup>

S
summer8999 已提交
587
publishDeviceDiscovery(publishInfo: PublishInfo): void
S
summer8999 已提交
588

S
summer8999 已提交
589
发布设备发现。
S
summer8999 已提交
590 591 592

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

@
@shi-xiaoxiao-iris 已提交
593
**参数:**
@
@shi-xiaoxiao-iris 已提交
594

S
summer8999 已提交
595
  | 名称          | 参数类型                        | 必填 | 说明    |
S
summer8999 已提交
596 597 598
  | ------------- | ------------------------------- | ---- | ----- |
  | publishInfo   | [PublishInfo](#publishinfo)     | 是   | 发布设备发现信息。 |

@
@shi-xiaoxiao-iris 已提交
599
**错误码:**
@
@shi-xiaoxiao-iris 已提交
600

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

@
@shi-xiaoxiao-iris 已提交
603
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
604 605 606
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600105 | Publish invalid.                                                |
@
@shi-xiaoxiao-iris 已提交
607

@
@shi-xiaoxiao-iris 已提交
608
**示例:**
@
@shi-xiaoxiao-iris 已提交
609

S
summer8999 已提交
610
  ```js
611
  // 生成发布标识,随机数确保每次调用发布接口的标识不一致
S
summer8999 已提交
612
  var publishId = Math.floor(Math.random() * 10000 + 1000);
S
summer8999 已提交
613
  var publishInfo = {
S
summer8999 已提交
614
      "publishId": publishId,
615 616 617
      "mode": 0xAA, // 主动模式
      "freq": 2,    // 高频率
      "ranging": 1  // 支持发现时测距
S
summer8999 已提交
618
  };
619 620 621
  try {
    dmInstance.publishDeviceDiscovery(publishInfo); // 当有发布结果时,通过回调通知给应用程序
  } catch (err) {
622
    console.error("publishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
623
  }
S
summer8999 已提交
624 625
  ```
  
S
summer8999 已提交
626
### unPublishDeviceDiscovery9+</sup>
S
summer8999 已提交
627

S
summer8999 已提交
628
unPublishDeviceDiscovery(publishId: number): void
S
summer8999 已提交
629 630 631 632 633

停止发布设备发现。

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

@
@shi-xiaoxiao-iris 已提交
634
**参数:**
@
@shi-xiaoxiao-iris 已提交
635

S
summer8999 已提交
636 637 638
  | 名称        | 参数类型 | 必填 | 说明  |
  | ----------- | -------- | ---- | ----- |
  | publishId   | number   | 是   | 发布标识。 |
S
summer8999 已提交
639

@
@shi-xiaoxiao-iris 已提交
640
**错误码:**
@
@shi-xiaoxiao-iris 已提交
641

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

@
@shi-xiaoxiao-iris 已提交
644
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
645 646
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
647

@
@shi-xiaoxiao-iris 已提交
648
**示例:**
@
@shi-xiaoxiao-iris 已提交
649

S
summer8999 已提交
650
  ```js
651
  // 入参需要和publishDeviceDiscovery接口传入的publishId配对使用
652
  try {
653
    dmInstance.unPublishDeviceDiscovery(publishId);
654
  } catch (err) {
655
    console.error("unPublishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
656
  }
S
summer8999 已提交
657 658
  ```

659 660 661 662 663 664 665 666
### authenticateDevice

authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback<{deviceId: string, pinToken ?: number}>): void

认证设备。

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

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

H
HelloCrease 已提交
669 670 671 672 673
  | 名称         | 参数类型                                     | 必填   | 说明      |
  | ---------- | ---------------------------------------- | ---- | ------- |
  | deviceInfo | [DeviceInfo](#deviceinfo)                | 是    | 设备信息。   |
  | authParam  | [AuthParam](#authparam)                  | 是    | 认证参数。   |
  | callback   | AsyncCallback<{ deviceId: string, pinToken ?: number }> | 是    | 认证结果回调。 |
674

@
@shi-xiaoxiao-iris 已提交
675
**错误码:**
@
@shi-xiaoxiao-iris 已提交
676

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

@
@shi-xiaoxiao-iris 已提交
679
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
680 681 682
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
| 11600103 | Authentication invalid.                                         |
@
@shi-xiaoxiao-iris 已提交
683

@
@shi-xiaoxiao-iris 已提交
684
**示例:**
@
@shi-xiaoxiao-iris 已提交
685

686
  ```js
687
  // 认证的设备信息,可以从发现的结果中获取
688 689 690 691 692 693
  var deviceInfo ={
      "deviceId": "XXXXXXXX",
      "deviceName": "",
      deviceType: 0x0E
  };
  let authParam = {
694
      "authType": 1, // 认证类型: 1 - 无账号PIN码认证
695 696
      "extraInfo": {} 
  }
697 698
  try {
    dmInstance.authenticateDevice(deviceInfo, authParam, (err, data) => {
699
      if (err) {
700
          console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
701 702
          return;
      }
@
@shi-xiaoxiao-iris 已提交
703 704
      console.info("authenticateDevice result:" + JSON.stringify(data));
      let token = data.pinToken;
705 706
    });
  } catch (err) {
707
    console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
708
  }
709 710 711 712 713 714 715 716 717 718
  ```

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

unAuthenticateDevice(deviceInfo: DeviceInfo): void

解除认证设备。

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

@
@shi-xiaoxiao-iris 已提交
719
**参数:**
@
@shi-xiaoxiao-iris 已提交
720

H
HelloCrease 已提交
721 722 723
  | 名称         | 参数类型                      | 必填   | 说明    |
  | ---------- | ------------------------- | ---- | ----- |
  | deviceInfo | [DeviceInfo](#deviceinfo) | 是    | 设备信息。 |
724

@
@shi-xiaoxiao-iris 已提交
725
**错误码:**
@
@shi-xiaoxiao-iris 已提交
726

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

@
@shi-xiaoxiao-iris 已提交
729
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
730 731
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
732

@
@shi-xiaoxiao-iris 已提交
733
**示例:**
@
@shi-xiaoxiao-iris 已提交
734

735
  ```js
736 737 738
  try {
    dmInstance.unAuthenticateDevice(deviceInfo);
  } catch (err) {
739
    console.error("unAuthenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
740
  }
741 742 743 744 745 746 747 748 749 750
  ```

### verifyAuthInfo

verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string, level: number}>): void

验证认证信息。

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

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

H
HelloCrease 已提交
753 754 755
  | 名称       | 参数类型                                     | 必填   | 说明      |
  | -------- | ---------------------------------------- | ---- | ------- |
  | authInfo | [AuthInfo](#authinfo)                    | 是    | 认证信息。   |
756
  | callback | AsyncCallback<{ deviceId: string, level: number }> | 是    | 验证结果回调。 |
757

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

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

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

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

768 769 770 771 772 773
  ```js
  let authInfo = {
    "authType": 1,
    "token": xxxxxx,
    "extraInfo": {}
  }
774 775
  try {
    dmInstance.verifyAuthInfo(authInfo, (err, data) => {
776
    if (err) {
777
        console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
778 779
        return;
    }
@
@shi-xiaoxiao-iris 已提交
780
    console.info("verifyAuthInfo result:" + JSON.stringify(data));
781 782
    });
  } catch (err) {
783
    console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
784
  }
785 786
  ```

@
@shi-xiaoxiao-iris 已提交
787
### setUserOperation9+</sup>
@
@shi-xiaoxiao-iris 已提交
788 789 790 791 792 793 794

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

设置用户ui操作行为。

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

@
@shi-xiaoxiao-iris 已提交
795
**参数:**
@
@shi-xiaoxiao-iris 已提交
796

797 798 799 800
  | 名称       | 参数类型            | 必填  | 说明                |
  | ------------- | --------------- | ---- | ------------------- |
  | operateAction | number          | 是    | 用户操作动作。       |
  | params        | string          | 是    | 表示用户的输入参数。 |
@
@shi-xiaoxiao-iris 已提交
801

@
@shi-xiaoxiao-iris 已提交
802
**示例:**
@
@shi-xiaoxiao-iris 已提交
803 804

  ```js
@
@shi-xiaoxiao-iris 已提交
805 806 807 808 809 810 811 812 813 814 815 816 817
 try {
    /*
      operateAction = 0 - 允许授权
      operateAction = 1 - 取消授权
      operateAction = 2 - 授权框用户操作超时
      operateAction = 3 - 取消pin码框展示
      operateAction = 4 - 取消pin码输入框展示
      operateAction = 5 - pin码输入框确定操作
    */
    let operation = 0;
    this.dmInstance.setUserOperation(operation, "extra")
    } catch (err) {
      console.error("setUserOperation errCode:" + err.code + ",errMessage:" + err.message);
@
@shi-xiaoxiao-iris 已提交
818 819 820
  }
  ```

@
@shi-xiaoxiao-iris 已提交
821
### on('uiStateChange')9+</sup>
@
@shi-xiaoxiao-iris 已提交
822 823 824 825 826 827 828

on(type: 'uiStateChange', callback: Callback<{ param: string}>): void;

ui状态变更回调。

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

@
@shi-xiaoxiao-iris 已提交
829
**参数:**
@
@shi-xiaoxiao-iris 已提交
830

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

@
@shi-xiaoxiao-iris 已提交
836
**示例:**
@
@shi-xiaoxiao-iris 已提交
837 838 839

  ```js
  try {
@
@shi-xiaoxiao-iris 已提交
840
    dmInstance.on('uiStateChange', (data) => {
@
@shi-xiaoxiao-iris 已提交
841 842 843 844 845 846 847 848 849 850 851 852 853
    console.log("uiStateChange executed, dialog closed" + JSON.stringify(data))
    var tmpStr = JSON.parse(data.param)
    this.isShow = tmpStr.verifyFailed
    console.log("uiStateChange executed, dialog closed" + this.isShow)
    if (!this.isShow) {
        this.destruction()
    }
  });
  } catch (err) {
    console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

@
@shi-xiaoxiao-iris 已提交
854
### off('uiStateChange')9+</sup>
@
@shi-xiaoxiao-iris 已提交
855 856 857 858 859 860 861

off(type: 'uiStateChange', callback?: Callback<{ param: string}>): void;

取消ui状态变更回调

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

@
@shi-xiaoxiao-iris 已提交
862
**参数:**
@
@shi-xiaoxiao-iris 已提交
863

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

@
@shi-xiaoxiao-iris 已提交
869
**示例:**
@
@shi-xiaoxiao-iris 已提交
870 871 872

  ```js
  try {
@
@shi-xiaoxiao-iris 已提交
873
    dmInstance.off('uiStateChange');
@
@shi-xiaoxiao-iris 已提交
874 875 876 877 878
  } catch (err) {
    console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

Z
zengyawen 已提交
879
### on('deviceStateChange')
Z
zengyawen 已提交
880

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

Z
zengyawen 已提交
883 884
注册设备状态回调。

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

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

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

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

896
  ```js
897 898 899 900 901
  try {
    dmInstance.on('deviceStateChange', (data) => {
      console.info("deviceStateChange on:" + JSON.stringify(data));
    });
  } catch (err) {
902
    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
903
  }
Z
zengyawen 已提交
904
  ```
Z
zengyawen 已提交
905

Z
zengyawen 已提交
906
### off('deviceStateChange')
Z
zengyawen 已提交
907

908
off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void
Z
zengyawen 已提交
909 910 911

取消注册设备状态回调。

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

@
@shi-xiaoxiao-iris 已提交
914
**参数:**
@
@shi-xiaoxiao-iris 已提交
915

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

@
@shi-xiaoxiao-iris 已提交
921
**示例:**
@
@shi-xiaoxiao-iris 已提交
922

923
  ```js
924 925 926 927 928
  try {
    dmInstance.off('deviceStateChange', (data) => {
      console.info('deviceStateChange' + JSON.stringify(data));
    });
  } catch (err) {
929
    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
930
  }
Z
zengyawen 已提交
931 932
  ```

933 934 935 936 937 938 939 940
### on('deviceFound')

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

注册发现设备回调监听。

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

@
@shi-xiaoxiao-iris 已提交
941
**参数:**
@
@shi-xiaoxiao-iris 已提交
942

H
HelloCrease 已提交
943 944 945 946
  | 名称       | 参数类型                                     | 必填   | 说明                         |
  | -------- | ---------------------------------------- | ---- | -------------------------- |
  | type     | string                                   | 是    | 注册设备发现回调,以便在发现周边设备时通知应用程序。 |
  | callback | Callback&lt;{&nbsp;subscribeId: number, device: DeviceInfo&nbsp;}&gt; | 是    | 注册设备发现的回调方法。               |
947

@
@shi-xiaoxiao-iris 已提交
948
**示例:**
@
@shi-xiaoxiao-iris 已提交
949

950
  ```js
951 952 953 954 955
  try {
    dmInstance.on('deviceFound', (data) => {
      console.info("deviceFound:" + JSON.stringify(data));
    });
  } catch (err) {
956
    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
957
  }
958 959 960 961 962 963 964 965 966 967
  ```

### off('deviceFound')

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

取消注册设备发现回调。

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

@
@shi-xiaoxiao-iris 已提交
968
**参数:**
@
@shi-xiaoxiao-iris 已提交
969

H
HelloCrease 已提交
970 971 972 973
  | 名称       | 参数类型                                     | 必填   | 说明                          |
  | -------- | ---------------------------------------- | ---- | --------------------------- |
  | type     | string                                   | 是    | 取消注册设备发现回调。                 |
  | callback | Callback&lt;{&nbsp;subscribeId: number, device: [DeviceInfo](#deviceinfo)&nbsp;}&gt; | 是    | 指示要取消注册的设备发现回调,返回设备状态和设备信息。 |
974

@
@shi-xiaoxiao-iris 已提交
975
**示例:**
@
@shi-xiaoxiao-iris 已提交
976

977
  ```js
978 979 980 981 982
  try {
    dmInstance.off('deviceFound', (data) => {
      console.info('deviceFound' + JSON.stringify(data));
    });
  } catch (err) {
983
    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
984
  }
985 986 987 988 989 990 991 992 993 994
  ```

### on('discoverFail')

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

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

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

@
@shi-xiaoxiao-iris 已提交
995
**参数:**
@
@shi-xiaoxiao-iris 已提交
996

H
HelloCrease 已提交
997 998 999 1000
  | 名称       | 参数类型                                     | 必填   | 说明                             |
  | -------- | ---------------------------------------- | ---- | ------------------------------ |
  | type     | string                                   | 是    | 注册设备发现失败回调,以便在发现周边设备失败时通知应用程序。 |
  | callback | Callback&lt;{&nbsp;subscribeId: number, reason: number&nbsp;}&gt; | 是    | 注册设备发现失败的回调方法。                 |
1001

@
@shi-xiaoxiao-iris 已提交
1002
**示例:**
@
@shi-xiaoxiao-iris 已提交
1003

1004
  ```js
1005 1006
  try {
    dmInstance.on('discoverFail', (data) => {
1007
        console.info("discoverFail on:" + JSON.stringify(data));
1008
    });
1009
  } catch (err) {
1010
    console.error("discoverFail errCode:" + err.code + ",errMessage:" + err.message);
1011
  }
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
  ```

### off('discoverFail')

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

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

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

@
@shi-xiaoxiao-iris 已提交
1022
**参数:**
@
@shi-xiaoxiao-iris 已提交
1023

H
HelloCrease 已提交
1024 1025 1026 1027
  | 名称       | 参数类型                                     | 必填   | 说明                |
  | -------- | ---------------------------------------- | ---- | ----------------- |
  | type     | string                                   | 是    | 取消注册设备发现失败回调。     |
  | callback | Callback&lt;{&nbsp;subscribeId: number, reason: number&nbsp;}&gt; | 是    | 指示要取消注册的设备发现失败回调。 |
1028

@
@shi-xiaoxiao-iris 已提交
1029
**示例:**
@
@shi-xiaoxiao-iris 已提交
1030

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

S
summer8999 已提交
1041
### on('publishSuccess')9+</sup>
S
summer8999 已提交
1042 1043 1044 1045 1046 1047 1048

on(type: 'publishSuccess', callback: Callback&lt;{ publishId: number }&gt;): void

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

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

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

S
summer8999 已提交
1051
  | 名称     | 参数类型                                 | 必填 | 说明                       |
S
summer8999 已提交
1052
  | -------- | ---------------------------------------- | ---- | -------------------------- |
S
summer8999 已提交
1053 1054
  | type     | string                                   | 是   | 注册发布设备成功回调,以便将发布成功时通知应用程序。 |
  | callback | Callback&lt;{ publishId: number }&gt;    | 是   | 注册设备发布成功的回调方法。               |
S
summer8999 已提交
1055

@
@shi-xiaoxiao-iris 已提交
1056

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

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

S
summer8999 已提交
1069
### off('publishSuccess')9+</sup>
S
summer8999 已提交
1070 1071 1072

off(type: 'publishSuccess', callback?: Callback&lt;{ publishId: number }&gt;): void

S
summer8999 已提交
1073
取消注册设备发布成功回调。
S
summer8999 已提交
1074 1075 1076

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

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

S
summer8999 已提交
1079
  | 名称     | 参数类型                                 | 必填 | 说明                          |
S
summer8999 已提交
1080
  | -------- | ---------------------------------------- | ---- | --------------------------- |
S
summer8999 已提交
1081 1082
  | type     | string                                   | 是   | 取消注册设备发布成功回调。                 |
  | callback | Callback&lt;{ publishId: number }&gt;    | 是   | 指示要取消注册的设备发布成功回调。 |
S
summer8999 已提交
1083

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

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

S
summer8999 已提交
1096
### on('publishFail')9+</sup>
S
summer8999 已提交
1097 1098 1099 1100 1101 1102 1103

on(type: 'publishFail', callback: Callback&lt;{ publishId: number, reason: number }&gt;): void

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

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

@
@shi-xiaoxiao-iris 已提交
1104
**参数:**
@
@shi-xiaoxiao-iris 已提交
1105

S
summer8999 已提交
1106 1107 1108 1109
  | 名称     | 参数类型                                              | 必填 | 说明                             |
  | -------- | ----------------------------------------------------- | ---- | ------------------------------ |
  | type     | string                                                | 是   | 注册设备发布失败回调,以便在发布设备失败时通知应用程序。 |
  | callback | Callback&lt;{ publishId: number, reason: number }&gt; | 是   | 注册设备发布失败的回调方法。                 |
S
summer8999 已提交
1110

@
@shi-xiaoxiao-iris 已提交
1111
**示例:**
@
@shi-xiaoxiao-iris 已提交
1112

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

S
summer8999 已提交
1123
### off('publishFail')9+</sup>
S
summer8999 已提交
1124 1125 1126

off(type: 'publishFail', callback?: Callback&lt;{ publishId: number, reason: number }&gt;): void

S
summer8999 已提交
1127
取消注册设备发布失败回调。
S
summer8999 已提交
1128 1129 1130

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

@
@shi-xiaoxiao-iris 已提交
1131
**参数:**
@
@shi-xiaoxiao-iris 已提交
1132

S
summer8999 已提交
1133 1134 1135
  | 名称     | 参数类型                                              | 必填 | 说明                |
  | -------- | ----------------------------------------------------- | ---- | ----------------- |
  | type     | string                                                | 是   | 取消注册设备发布失败回调。     |
S
summer8999 已提交
1136
  | callback | Callback&lt;{ publishId: number, reason: number }&gt; | 是   | 指示要取消注册设备发布失败回调。 |
S
summer8999 已提交
1137

@
@shi-xiaoxiao-iris 已提交
1138
**示例:**
@
@shi-xiaoxiao-iris 已提交
1139

S
summer8999 已提交
1140
  ```js
1141 1142 1143 1144 1145
  try {
    dmInstance.off('publishFail', (data) => {
      console.info('publishFail' + JSON.stringify(data));
    });
  } catch (err) {
1146
    console.error("publishFail errCode:" + err.code + ",errMessage:" + err.message);
1147
  }
S
summer8999 已提交
1148
  ```
1149

Z
zengyawen 已提交
1150 1151 1152
### on('serviceDie')

on(type: 'serviceDie', callback: () =&gt; void): void
Z
zengyawen 已提交
1153 1154 1155

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

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

@
@shi-xiaoxiao-iris 已提交
1158
**参数:**
@
@shi-xiaoxiao-iris 已提交
1159

H
HelloCrease 已提交
1160 1161 1162 1163
  | 名称       | 参数类型                    | 必填   | 说明                                       |
  | -------- | ----------------------- | ---- | ---------------------------------------- |
  | type     | string                  | 是    | 注册serviceDie回调,以便在devicemanager服务异常终止时通知应用程序。 |
  | callback | ()&nbsp;=&gt;&nbsp;void | 是    | 注册serviceDie的回调方法。                       |
Z
zengyawen 已提交
1164

@
@shi-xiaoxiao-iris 已提交
1165
**示例:**
@
@shi-xiaoxiao-iris 已提交
1166

1167
  ```js
1168 1169 1170 1171 1172
  try {
    dmInstance.on("serviceDie", () => {
      console.info("serviceDie on");
    });
  } catch (err) {
1173
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1174
  }
Z
zengyawen 已提交
1175
  ```
Z
zengyawen 已提交
1176

Z
zengyawen 已提交
1177 1178 1179 1180 1181
### off('serviceDie')

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

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

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

@
@shi-xiaoxiao-iris 已提交
1185
**参数:**
@
@shi-xiaoxiao-iris 已提交
1186

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

@
@shi-xiaoxiao-iris 已提交
1192
**示例:**
@
@shi-xiaoxiao-iris 已提交
1193

1194
  ```js
1195 1196 1197 1198 1199
  try {
    dmInstance.off("serviceDie", () => {
      console.info("serviceDie off");
    });
  } catch (err) {
1200
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1201
  }
1202
  ```