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

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

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

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

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

Z
zengyawen 已提交
19 20

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

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


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

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

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

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

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

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

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

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

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

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

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

68
## DeviceInfo
Z
zengyawen 已提交
69

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

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

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

## DeviceType
Z
zengyawen 已提交
83 84 85

表示设备类型的枚举类。

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

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

Z
zengyawen 已提交
98

99
## DeviceStateChangeAction
Z
zengyawen 已提交
100

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

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

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

## SubscribeInfo

发现信息。
Z
zengyawen 已提交
115

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

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


## DiscoverMode 

表示发现模式的枚举。

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

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


## ExchangeMedium 

表示发现类型的枚举。

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

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

## ExchangeFreq 

表示发现频率的枚举。

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

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


## SubscribeCap 

表示发现能力的枚举。

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

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


## AuthParam

认证参数。

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

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

## AuthInfo

认证信息。

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

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

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

发布设备参数

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

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

## DeviceManager
Z
zengyawen 已提交
217 218 219

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo)

同步获取本地设备信息。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

startDeviceDiscovery(subscribeInfo: SubscribeInfo): void

发现周边设备。

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

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

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

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

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

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

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

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

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

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

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

发现周边设备。

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

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

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

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

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

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

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

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

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

564 565 566 567 568 569
### stopDeviceDiscovery

stopDeviceDiscovery(subscribeId: number): void

停止发现周边设备。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

停止发布设备发现。

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

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

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

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

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

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

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

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

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

677 678
### authenticateDevice

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

认证设备。

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

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

@
@shi-xiaoxiao-iris 已提交
687
**参数:**
@
@shi-xiaoxiao-iris 已提交
688

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

@
@shi-xiaoxiao-iris 已提交
695
**错误码:**
@
@shi-xiaoxiao-iris 已提交
696

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

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

@
@shi-xiaoxiao-iris 已提交
704
**示例:**
@
@shi-xiaoxiao-iris 已提交
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
          return;
      }
@
@shi-xiaoxiao-iris 已提交
723 724
      console.info("authenticateDevice result:" + JSON.stringify(data));
      let 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
  ```

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

unAuthenticateDevice(deviceInfo: DeviceInfo): void

解除认证设备。

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

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

@
@shi-xiaoxiao-iris 已提交
741
**参数:**
@
@shi-xiaoxiao-iris 已提交
742

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

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

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

@
@shi-xiaoxiao-iris 已提交
751
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
752 753
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
754

@
@shi-xiaoxiao-iris 已提交
755
**示例:**
@
@shi-xiaoxiao-iris 已提交
756

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

### verifyAuthInfo

767
verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback&lt;{deviceId: string, level: number}&gt;): void
768 769 770

验证认证信息。

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

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
786
| 错误码ID | 错误信息                                                        |
@
@shi-xiaoxiao-iris 已提交
787 788
| -------- | --------------------------------------------------------------- |
| 11600101 | Failed to execute the function.                                 |
@
@shi-xiaoxiao-iris 已提交
789

@
@shi-xiaoxiao-iris 已提交
790
**示例:**
@
@shi-xiaoxiao-iris 已提交
791

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

@
@shi-xiaoxiao-iris 已提交
811
### setUserOperation<sup>9+</sup>
@
@shi-xiaoxiao-iris 已提交
812 813 814 815 816

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

设置用户ui操作行为。

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

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

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

@
@shi-xiaoxiao-iris 已提交
823
  | 参数名       | 类型            | 必填  | 说明                |
824 825 826
  | ------------- | --------------- | ---- | ------------------- |
  | operateAction | number          | 是    | 用户操作动作。       |
  | params        | string          | 是    | 表示用户的输入参数。 |
@
@shi-xiaoxiao-iris 已提交
827

@
@shi-xiaoxiao-iris 已提交
828
**示例:**
@
@shi-xiaoxiao-iris 已提交
829 830

  ```js
@
@shi-xiaoxiao-iris 已提交
831 832 833 834 835 836 837 838 839 840 841 842 843
 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 已提交
844 845 846
  }
  ```

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

849
on(type: 'uiStateChange', callback: Callback&lt;{ param: string}&gt;): void;
@
@shi-xiaoxiao-iris 已提交
850 851 852

ui状态变更回调。

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
864
**示例:**
@
@shi-xiaoxiao-iris 已提交
865 866 867

  ```js
  try {
@
@shi-xiaoxiao-iris 已提交
868
    dmInstance.on('uiStateChange', (data) => {
@
@shi-xiaoxiao-iris 已提交
869 870 871 872 873 874 875 876 877 878 879 880 881
    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 已提交
882
### off('uiStateChange')<sup>9+</sup>
@
@shi-xiaoxiao-iris 已提交
883

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

886 887 888
取消ui状态变更回调。

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
899
**示例:**
@
@shi-xiaoxiao-iris 已提交
900 901 902

  ```js
  try {
@
@shi-xiaoxiao-iris 已提交
903
    dmInstance.off('uiStateChange');
@
@shi-xiaoxiao-iris 已提交
904 905 906 907 908
  } catch (err) {
    console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

Z
zengyawen 已提交
909
### on('deviceStateChange')
Z
zengyawen 已提交
910

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

Z
zengyawen 已提交
913 914
注册设备状态回调。

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

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

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

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

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

928
  ```js
929 930 931 932 933
  try {
    dmInstance.on('deviceStateChange', (data) => {
      console.info("deviceStateChange on:" + JSON.stringify(data));
    });
  } catch (err) {
934
    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
935
  }
Z
zengyawen 已提交
936
  ```
Z
zengyawen 已提交
937

Z
zengyawen 已提交
938
### off('deviceStateChange')
Z
zengyawen 已提交
939

940
off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void
Z
zengyawen 已提交
941 942 943

取消注册设备状态回调。

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

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

@
@shi-xiaoxiao-iris 已提交
948
**参数:**
@
@shi-xiaoxiao-iris 已提交
949

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

@
@shi-xiaoxiao-iris 已提交
955
**示例:**
@
@shi-xiaoxiao-iris 已提交
956

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

967 968
### on('deviceFound')

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

注册发现设备回调监听。

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

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

@
@shi-xiaoxiao-iris 已提交
977
**参数:**
@
@shi-xiaoxiao-iris 已提交
978

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

@
@shi-xiaoxiao-iris 已提交
984
**示例:**
@
@shi-xiaoxiao-iris 已提交
985

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

### off('deviceFound')

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

取消注册设备发现回调。

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

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

@
@shi-xiaoxiao-iris 已提交
1006
**参数:**
@
@shi-xiaoxiao-iris 已提交
1007

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

@
@shi-xiaoxiao-iris 已提交
1013
**示例:**
@
@shi-xiaoxiao-iris 已提交
1014

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

### on('discoverFail')

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
1035
**参数:**
@
@shi-xiaoxiao-iris 已提交
1036

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

@
@shi-xiaoxiao-iris 已提交
1042
**示例:**
@
@shi-xiaoxiao-iris 已提交
1043

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

### off('discoverFail')

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
1064
**参数:**
@
@shi-xiaoxiao-iris 已提交
1065

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

@
@shi-xiaoxiao-iris 已提交
1071
**示例:**
@
@shi-xiaoxiao-iris 已提交
1072

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

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

1085
on(type: 'publishSuccess', callback: Callback&lt;{ publishId: number }&gt;): void
S
summer8999 已提交
1086 1087 1088

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

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

S
summer8999 已提交
1091 1092
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1093
**参数:**
@
@shi-xiaoxiao-iris 已提交
1094

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

@
@shi-xiaoxiao-iris 已提交
1100

@
@shi-xiaoxiao-iris 已提交
1101
**示例:**
@
@shi-xiaoxiao-iris 已提交
1102

S
summer8999 已提交
1103
  ```js
1104 1105 1106 1107 1108
  try {
    dmInstance.on('publishSuccess', (data) => {
      console.info("publishSuccess:" + JSON.stringify(data));
    });
  } catch (err) {
1109
    console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message);
1110
  }
S
summer8999 已提交
1111 1112
  ```

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

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

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

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

S
summer8999 已提交
1121 1122
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1123
**参数:**
@
@shi-xiaoxiao-iris 已提交
1124

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

@
@shi-xiaoxiao-iris 已提交
1130
**示例:**
@
@shi-xiaoxiao-iris 已提交
1131

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

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

1144
on(type: 'publishFail', callback: Callback&lt;{ publishId: number, reason: number }&gt;): void
S
summer8999 已提交
1145 1146 1147

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

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

S
summer8999 已提交
1150 1151
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1152
**参数:**
@
@shi-xiaoxiao-iris 已提交
1153

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

@
@shi-xiaoxiao-iris 已提交
1159
**示例:**
@
@shi-xiaoxiao-iris 已提交
1160

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

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

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

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

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

S
summer8999 已提交
1179 1180
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1181
**参数:**
@
@shi-xiaoxiao-iris 已提交
1182

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

@
@shi-xiaoxiao-iris 已提交
1188
**示例:**
@
@shi-xiaoxiao-iris 已提交
1189

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

Z
zengyawen 已提交
1200 1201 1202
### on('serviceDie')

on(type: 'serviceDie', callback: () =&gt; void): void
Z
zengyawen 已提交
1203 1204 1205

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

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
1217
**示例:**
@
@shi-xiaoxiao-iris 已提交
1218

1219
  ```js
1220 1221 1222 1223 1224
  try {
    dmInstance.on("serviceDie", () => {
      console.info("serviceDie on");
    });
  } catch (err) {
1225
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1226
  }
Z
zengyawen 已提交
1227
  ```
Z
zengyawen 已提交
1228

Z
zengyawen 已提交
1229 1230 1231 1232 1233
### off('serviceDie')

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
1239
**参数:**
@
@shi-xiaoxiao-iris 已提交
1240

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

@
@shi-xiaoxiao-iris 已提交
1246
**示例:**
@
@shi-xiaoxiao-iris 已提交
1247

1248
  ```js
1249 1250 1251 1252 1253
  try {
    dmInstance.off("serviceDie", () => {
      console.info("serviceDie off");
    });
  } catch (err) {
1254
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1255
  }
1256
  ```