js-apis-device-manager.md 45.4 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开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口为系统接口,三方应用不支持调用。
Z
zengyawen 已提交
21

Z
zengyawen 已提交
22 23

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

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


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

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

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

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

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

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

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

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
49 50 51 52 53
| 类型      | 说明                                                           |
| -------- | --------------------------------------------------------------- |
| 401      | Input parameter error.                                          |
| 11600101 | Failed to execute the function.                                 |
| 11600102 | Failed to obtain the service.                                   |
@
@shi-xiaoxiao-iris 已提交
54 55 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 233 234 235
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
236
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
237 238 239 240 241
| ------- | --------------------------------------------------------------- |
| 11600101| Failed to execute the function.                                 |

**示例**

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 259
**返回值**

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

@
@shi-xiaoxiao-iris 已提交
264 265 266 267 268 269 270 271 272 273
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

| 类型     | 说明                                                           |
| ------- | --------------------------------------------------------------- |
| 11600101| Failed to execute the function.                                 |

**示例**

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 291
**参数**

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

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

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
300
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
301 302 303 304 305 306
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |
| 11600101| Failed to execute the function.                                 |

**示例**

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

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

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
335 336 337 338 339 340 341 342 343 344
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

| 类型     | 说明                                                           |
| ------- | --------------------------------------------------------------- |
| 11600101| Failed to execute the function.                                 |

**示例**

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

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

getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo)

同步获取本地设备信息。

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

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

H
HelloCrease 已提交
363 364
  | 名称                                     | 说明        |
  | -------------------------------------- | --------- |
365
  | Array&lt;[DeviceInfo](#deviceinfo)&gt; | 返回本地设备列表。 |
366

@
@shi-xiaoxiao-iris 已提交
367 368 369 370 371 372 373 374 375 376
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

| 类型     | 说明                                                           |
| ------- | --------------------------------------------------------------- |
| 11600101| Failed to execute the function.                                 |

**示例**

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

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

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
399 400 401 402
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
403
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
404 405 406 407 408 409
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |
| 11600101| Failed to execute the function.                                 |

**示例**

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

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
437 438 439 440 441 442 443 444 445 446
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

| 类型     | 说明                                                           |
| ------- | --------------------------------------------------------------- |
| 11600101| Failed to execute the function.                                 |

**示例**

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

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

startDeviceDiscovery(subscribeInfo: SubscribeInfo): void

发现周边设备。

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

@
@shi-xiaoxiao-iris 已提交
464 465
**参数**

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

@
@shi-xiaoxiao-iris 已提交
470 471 472 473
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
474
| 类型      | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
475 476 477 478
| -------- | --------------------------------------------------------------- |
| 401      | Input parameter error.                                          |
| 201      | Permission verify failed.                                       |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
479
| 11600102 | Failed to obtain the service.                                   |
@
@shi-xiaoxiao-iris 已提交
480 481 482 483
| 11600104 | Discovery invalid.                                              |

**示例**

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

S
summer8999 已提交
503 504
### startDeviceDiscovery9+</sup>

S
summer8999 已提交
505
startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void
S
summer8999 已提交
506 507 508 509 510

发现周边设备。

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

@
@shi-xiaoxiao-iris 已提交
511 512
**参数**

S
summer8999 已提交
513 514 515
  | 名称            | 参数类型                            | 必填   | 说明    |
  | ------------- | ------------------------------- | ---- | ----- |
  | subscribeInfo | [SubscribeInfo](#subscribeinfo) | 是   | 发现信息。 |
S
summer8999 已提交
516
  | filterOptions | string        | 否   | 发现设备过滤信息。|
S
summer8999 已提交
517

@
@shi-xiaoxiao-iris 已提交
518 519 520 521
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
522
| 类型      | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
523 524 525 526
| -------- | --------------------------------------------------------------- |
| 401      | Input parameter error.                                          |
| 201      | Permission verify failed.                                       |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
527
| 11600102 | Failed to obtain the service.                                   |
@
@shi-xiaoxiao-iris 已提交
528 529 530 531
| 11600104 | Discovery invalid.                                              |

**示例**

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

560 561 562 563 564 565 566 567
### stopDeviceDiscovery

stopDeviceDiscovery(subscribeId: number): void

停止发现周边设备。

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

@
@shi-xiaoxiao-iris 已提交
568 569
**参数**

H
HelloCrease 已提交
570 571 572
  | 名称          | 参数类型   | 必填   | 说明    |
  | ----------- | ------ | ---- | ----- |
  | subscribeId | number | 是    | 发现标识。 |
573

@
@shi-xiaoxiao-iris 已提交
574 575 576 577
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
578 579 580 581 582 583
| 类型      | 说明                                                           |
| -------- | --------------------------------------------------------------- |
| 401      | Input parameter error.                                          |
| 201      | Permission verify failed.                                       |
| 11600101 | Failed to execute the function.                                 |
| 11600102 | Failed to obtain the service.                                   |
@
@shi-xiaoxiao-iris 已提交
584 585 586

**示例**

587
  ```js
588
  // 入参需要和startDeviceDiscovery接口传入的subscribeId配对使用
589 590 591
  try {
    dmInstance.stopDeviceDiscovery(subscribeId);
  } catch (err) {
592
    console.error("stopDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
593
  }
594 595
  ```

S
summer8999 已提交
596 597
### publishDeviceDiscovery9+</sup>

S
summer8999 已提交
598
publishDeviceDiscovery(publishInfo: PublishInfo): void
S
summer8999 已提交
599

S
summer8999 已提交
600
发布设备发现。
S
summer8999 已提交
601 602 603

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

@
@shi-xiaoxiao-iris 已提交
604 605
**参数**

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

@
@shi-xiaoxiao-iris 已提交
610 611 612 613
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
614 615 616 617 618 619 620
| 类型     | 说明                                                           |
| -------- | --------------------------------------------------------------- |
| 401      | Input parameter error.                                          |
| 201      | Permission verify failed.                                       |
| 11600101 | Failed to execute the function.                                 |
| 11600102 | Failed to obtain the service.                                   |
| 11600105 | Publish invalid.                                                |
@
@shi-xiaoxiao-iris 已提交
621 622 623

**示例**

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

S
summer8999 已提交
642
unPublishDeviceDiscovery(publishId: number): void
S
summer8999 已提交
643 644 645 646 647

停止发布设备发现。

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

@
@shi-xiaoxiao-iris 已提交
648 649
**参数**

S
summer8999 已提交
650 651 652
  | 名称        | 参数类型 | 必填 | 说明  |
  | ----------- | -------- | ---- | ----- |
  | publishId   | number   | 是   | 发布标识。 |
S
summer8999 已提交
653

@
@shi-xiaoxiao-iris 已提交
654 655 656 657
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
658 659 660 661 662 663
| 类型     | 说明                                                           |
| -------- | --------------------------------------------------------------- |
| 401      | Input parameter error.                                          |
| 201      | Permission verify failed.                                       |
| 11600101 | Failed to execute the function.                                 |
| 11600102 | Failed to obtain the service.                                   |
@
@shi-xiaoxiao-iris 已提交
664 665 666

**示例**

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

676 677 678 679 680 681 682 683
### authenticateDevice

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

认证设备。

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

@
@shi-xiaoxiao-iris 已提交
684 685
**参数**

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

@
@shi-xiaoxiao-iris 已提交
692 693 694 695
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
696 697 698 699 700 701 702
| 类型      | 说明                                                           |
| -------- | --------------------------------------------------------------- |
| 401      | Input parameter error.                                          |
| 201      | Permission verify failed.                                       |
| 11600101 | Failed to execute the function.                                 |
| 11600102 | Failed to obtain the service.                                   |
| 11600103 | Authentication invalid.                                         |
@
@shi-xiaoxiao-iris 已提交
703 704 705

**示例**

706
  ```js
707
  // 认证的设备信息,可以从发现的结果中获取
708 709 710 711 712 713
  var deviceInfo ={
      "deviceId": "XXXXXXXX",
      "deviceName": "",
      deviceType: 0x0E
  };
  let authParam = {
714
      "authType": 1, // 认证类型: 1 - 无账号PIN码认证
715 716
      "extraInfo": {} 
  }
717 718
  try {
    dmInstance.authenticateDevice(deviceInfo, authParam, (err, data) => {
719
      if (err) {
720
          console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
721 722 723 724
          return;
      }
      console.info(TAG + "authenticateDevice result:" + JSON.stringify(data));
      token = data.pinToken;
725 726
    });
  } catch (err) {
727
    console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
728
  }
729 730 731 732 733 734 735 736 737 738
  ```

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

unAuthenticateDevice(deviceInfo: DeviceInfo): void

解除认证设备。

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

@
@shi-xiaoxiao-iris 已提交
739 740
**参数**

H
HelloCrease 已提交
741 742 743
  | 名称         | 参数类型                      | 必填   | 说明    |
  | ---------- | ------------------------- | ---- | ----- |
  | deviceInfo | [DeviceInfo](#deviceinfo) | 是    | 设备信息。 |
744

@
@shi-xiaoxiao-iris 已提交
745 746 747 748
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
749 750 751 752 753 754
| 类型     | 说明                                                           |
| -------- | --------------------------------------------------------------- |
| 401      | Input parameter error.                                          |
| 201      | Permission verify failed.                                       |
| 11600101 | Failed to execute the function.                                 |
| 11600102 | Failed to obtain the service.                                   |
@
@shi-xiaoxiao-iris 已提交
755 756 757

**示例**

758
  ```js
759 760 761
  try {
    dmInstance.unAuthenticateDevice(deviceInfo);
  } catch (err) {
762
    console.error("unAuthenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
763
  }
764 765 766 767 768 769 770 771 772 773
  ```

### verifyAuthInfo

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

验证认证信息。

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

@
@shi-xiaoxiao-iris 已提交
774 775
**参数**

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

@
@shi-xiaoxiao-iris 已提交
781 782 783 784
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
785 786 787 788 789 790
| 类型      | 说明                                                           |
| -------- | --------------------------------------------------------------- |
| 401      | Input parameter error.                                          |
| 201      | Permission verify failed.                                       |
| 11600101 | Failed to execute the function.                                 |
| 11600102 | Failed to obtain the service.                                   |
@
@shi-xiaoxiao-iris 已提交
791 792 793

**示例**

794 795 796 797 798 799
  ```js
  let authInfo = {
    "authType": 1,
    "token": xxxxxx,
    "extraInfo": {}
  }
800 801
  try {
    dmInstance.verifyAuthInfo(authInfo, (err, data) => {
802
    if (err) {
803
        console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
804 805 806
        return;
    }
    console.info(TAG + "verifyAuthInfo result:" + JSON.stringify(data));
807 808
    });
  } catch (err) {
809
    console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
810
  }
811 812
  ```

Z
zengyawen 已提交
813
### on('deviceStateChange')
Z
zengyawen 已提交
814

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

Z
zengyawen 已提交
817 818
注册设备状态回调。

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

@
@shi-xiaoxiao-iris 已提交
821 822
**参数**

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

@
@shi-xiaoxiao-iris 已提交
828 829 830 831
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
832
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
833 834 835 836 837
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

838
  ```js
839 840 841 842 843
  try {
    dmInstance.on('deviceStateChange', (data) => {
      console.info("deviceStateChange on:" + JSON.stringify(data));
    });
  } catch (err) {
844
    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
845
  }
Z
zengyawen 已提交
846
  ```
Z
zengyawen 已提交
847 848


Z
zengyawen 已提交
849
### off('deviceStateChange')
Z
zengyawen 已提交
850

851
off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void
Z
zengyawen 已提交
852 853 854

取消注册设备状态回调。

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

@
@shi-xiaoxiao-iris 已提交
857 858
**参数**

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

@
@shi-xiaoxiao-iris 已提交
864 865 866 867
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
868
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
869 870 871 872 873
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

874
  ```js
875 876 877 878 879
  try {
    dmInstance.off('deviceStateChange', (data) => {
      console.info('deviceStateChange' + JSON.stringify(data));
    });
  } catch (err) {
880
    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
881
  }
Z
zengyawen 已提交
882 883 884
  ```


885 886 887 888 889 890 891 892
### on('deviceFound')

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

注册发现设备回调监听。

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

@
@shi-xiaoxiao-iris 已提交
893 894
**参数**

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

@
@shi-xiaoxiao-iris 已提交
900 901 902 903
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
904
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
905 906 907 908 909
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

910
  ```js
911 912 913 914 915
  try {
    dmInstance.on('deviceFound', (data) => {
      console.info("deviceFound:" + JSON.stringify(data));
    });
  } catch (err) {
916
    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
917
  }
918 919 920 921 922 923 924 925 926 927
  ```

### off('deviceFound')

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

取消注册设备发现回调。

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

@
@shi-xiaoxiao-iris 已提交
928 929
**参数**

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

@
@shi-xiaoxiao-iris 已提交
935 936 937 938
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
939
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
940 941 942 943 944
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

945
  ```js
946 947 948 949 950
  try {
    dmInstance.off('deviceFound', (data) => {
      console.info('deviceFound' + JSON.stringify(data));
    });
  } catch (err) {
951
    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
952
  }
953 954 955 956 957 958 959 960 961 962
  ```

### on('discoverFail')

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
970 971 972 973
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
974
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
975 976 977 978 979
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

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

### off('discoverFail')

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

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

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

@
@shi-xiaoxiao-iris 已提交
998 999
**参数**

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

@
@shi-xiaoxiao-iris 已提交
1005 1006 1007 1008
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
1009
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
1010 1011 1012 1013 1014
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

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

S
summer8999 已提交
1025
### on('publishSuccess')9+</sup>
S
summer8999 已提交
1026 1027 1028 1029 1030 1031 1032

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
1040 1041 1042 1043
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
1044
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
1045 1046 1047 1048 1049
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

S
summer8999 已提交
1050
  ```js
1051 1052 1053 1054 1055
  try {
    dmInstance.on('publishSuccess', (data) => {
      console.info("publishSuccess:" + JSON.stringify(data));
    });
  } catch (err) {
1056
    console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message);
1057
  }
S
summer8999 已提交
1058 1059
  ```

S
summer8999 已提交
1060
### off('publishSuccess')9+</sup>
S
summer8999 已提交
1061 1062 1063

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

S
summer8999 已提交
1064
取消注册设备发布成功回调。
S
summer8999 已提交
1065 1066 1067

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

@
@shi-xiaoxiao-iris 已提交
1068 1069
**参数**

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

@
@shi-xiaoxiao-iris 已提交
1075 1076 1077 1078
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
1079
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
1080 1081 1082 1083 1084
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

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

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

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
1110 1111 1112 1113
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
1114
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
1115 1116 1117 1118 1119
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

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

S
summer8999 已提交
1130
### off('publishFail')9+</sup>
S
summer8999 已提交
1131 1132 1133

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

S
summer8999 已提交
1134
取消注册设备发布失败回调。
S
summer8999 已提交
1135 1136 1137

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

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

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

@
@shi-xiaoxiao-iris 已提交
1145 1146 1147 1148
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
1149
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
1150 1151 1152 1153 1154
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

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

Z
zengyawen 已提交
1165 1166 1167
### on('serviceDie')

on(type: 'serviceDie', callback: () =&gt; void): void
Z
zengyawen 已提交
1168 1169 1170

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

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

@
@shi-xiaoxiao-iris 已提交
1173 1174
**参数**

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

@
@shi-xiaoxiao-iris 已提交
1180 1181 1182 1183
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
1184
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
1185 1186 1187 1188 1189
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

1190
  ```js
1191 1192 1193 1194 1195
  try {
    dmInstance.on("serviceDie", () => {
      console.info("serviceDie on");
    });
  } catch (err) {
1196
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1197
  }
Z
zengyawen 已提交
1198
  ```
Z
zengyawen 已提交
1199 1200


Z
zengyawen 已提交
1201 1202 1203 1204 1205
### off('serviceDie')

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
1216 1217 1218 1219
**错误码**

以下的错误码的详细介绍请参见[分布式硬件子系统错误码](../errorcodes/errorcode-device-manager.md)

@
@shi-xiaoxiao-iris 已提交
1220
| 类型     | 说明                                                           |
@
@shi-xiaoxiao-iris 已提交
1221 1222 1223 1224 1225
| ------- | --------------------------------------------------------------- |
| 401     | Input parameter error.                                          |

**示例**

1226
  ```js
1227 1228 1229 1230 1231
  try {
    dmInstance.off("serviceDie", () => {
      console.info("serviceDie off");
    });
  } catch (err) {
1232
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1233
  }
1234
  ```