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

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

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

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

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

Z
zengyawen 已提交
19 20

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

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


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

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

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

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

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

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

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

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

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

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

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

68
## DeviceInfo
Z
zengyawen 已提交
69

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

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

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

## DeviceType
Z
zengyawen 已提交
84 85 86

表示设备类型的枚举类。

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

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

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

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

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

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

112
## DeviceStateChangeAction
Z
zengyawen 已提交
113

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

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

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

## SubscribeInfo

发现信息。
Z
zengyawen 已提交
128

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

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


## DiscoverMode 

表示发现模式的枚举。

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

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


## ExchangeMedium 

表示发现类型的枚举。

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

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

## ExchangeFreq 

表示发现频率的枚举。

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

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


## SubscribeCap 

表示发现能力的枚举。

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

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


## AuthParam

认证参数。

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

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

## AuthInfo

认证信息。

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

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

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

发布设备参数

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

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

## DeviceManager
Z
zengyawen 已提交
230 231 232

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo)

同步获取本地设备信息。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

startDeviceDiscovery(subscribeInfo: SubscribeInfo): void

发现周边设备。

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

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

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

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

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

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

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

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

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

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

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

发现周边设备。

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

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

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

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

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

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

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

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

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

577 578 579 580 581 582
### stopDeviceDiscovery

stopDeviceDiscovery(subscribeId: number): void

停止发现周边设备。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

停止发布设备发现。

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

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

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

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

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

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

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

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

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

692 693
### authenticateDevice

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

认证设备。

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

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

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

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

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

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

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

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

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

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

unAuthenticateDevice(deviceInfo: DeviceInfo): void

解除认证设备。

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

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

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

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

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

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

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

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

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

### verifyAuthInfo

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

验证认证信息。

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

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

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

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

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

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

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

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

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

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

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

设置用户ui操作行为。

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

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

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

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

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

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

W
wuqi0105 已提交
877
### requestCredentialRegisterInfo<sup>10+</sup>
W
wuqi0105 已提交
878

W
wuqi0105 已提交
879
requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{registerInfo: string}>): void;
W
wuqi0105 已提交
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901

获取凭据的注册信息。

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

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

**参数:**

  | 参数名       | 类型            | 必填  | 说明                |
  | ------------- | --------------- | ---- | ------------------- |
  | requestInfo   | string          | 是    | 请求凭据信息。       |
  | callback      | AsyncCallback<{registerInfo: string}>         | 是    | 凭据的注册信息回调。 |

**示例:**

  ```js
  let credentialInfo = {
    "version" : "1.2.3",
    "userId" : "123"
  }
  try {
W
wuqi0105 已提交
902
    dmClass.requestCredentialRegisterInfo(credentialInfo, (data) => {
W
wuqi0105 已提交
903
      if (data) {
W
wuqi0105 已提交
904
          console.info("requestCredentialRegisterInfo result:" + JSON.stringify(data));
W
wuqi0105 已提交
905
      } else {
W
wuqi0105 已提交
906
          console.info.push("requestCredentialRegisterInfo result: data is null");
W
wuqi0105 已提交
907 908 909
      }
    });
  } catch (err) {
W
wuqi0105 已提交
910
    console.error("requestCredentialRegisterInfo err:" + err.code + "," + err.message);
W
wuqi0105 已提交
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
  }
  ```

### importCredential<sup>10+</sup>

importCredential(credentialInfo: string, callback: AsyncCallback<{resultInfo: string}>): void;

导入凭据信息。

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

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

**参数:**

  | 参数名       | 类型            | 必填  | 说明                |
  | ------------- | --------------- | ---- | ------------------- |
  | credentialInfo| string          | 是    | 导入凭据信息。       |
  | callback      | AsyncCallback<{resultInfo: string}>           | 是    | 导入凭据结果回调。 |

**示例:**

  ```js
  let credentialInfo = {
    "processType" : 1,
    "authType" : 1,
    "userId" : "123",
    "deviceId" : "aaa",
    "version" : "1.2.3",
    "devicePk" : "0000",
    "credentialData" : 
    [
      {
        "credentialType" : 2,
        "credentialId" : "102",
        "serverPk" : "3059301306072A8648CE3D020106082A8648CE3D03",
        "pkInfoSignature" : "30440220490BCB4F822004C9A76AB8D97F80041FC0E",
        "pkInfo" : "",
        "authCode" : "",
        "peerDeviceId" : ""
      }
    ]
  }
  try {
    dmClass.importCredential(credentialInfo, (data) => {
      if (data) {
          console.info("importCredential result:" + JSON.stringify(data));
      } else {
          console.info.push("importCredential result: data is null");
      }
    });
  } catch (err) {
    console.error("importCredential err:" + err.code + "," + err.message);
  }
  ```

### deleteCredential<sup>10+</sup>

deleteCredential(queryInfo: string, callback: AsyncCallback<{resultInfo: string}>): void;

删除凭据信息。

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

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

**参数:**

  | 参数名       | 类型            | 必填  | 说明                |
  | ------------- | --------------- | ---- | ------------------- |
  | queryInfo     | string          | 是    | 删除凭据信息。       |
  | callback      | AsyncCallback<{resultInfo: string}>           | 是    | 删除凭据结果回调。 |

**示例:**

  ```js
  let queryInfo = {
    "processType" : 1,
    "authType" : 1,
    "userId" : "123"
  }
  try {
    dmClass.deleteCredential(queryInfo, (data) => {
      if (data) {
          console.info("deleteCredential result:" + JSON.stringify(data));
      } else {
          console.info.push("deleteCredential result: data is null");
      }
    });
  } catch (err) {
    console.error("deleteCredential err:" + err.code + "," + err.message);
  }
  ```

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

1007
on(type: 'uiStateChange', callback: Callback&lt;{ param: string}&gt;): void;
@
@shi-xiaoxiao-iris 已提交
1008 1009 1010

ui状态变更回调。

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

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

@
@shi-xiaoxiao-iris 已提交
1015
**参数:**
@
@shi-xiaoxiao-iris 已提交
1016

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

@
@shi-xiaoxiao-iris 已提交
1022
**示例:**
@
@shi-xiaoxiao-iris 已提交
1023 1024 1025

  ```js
  try {
@
@shi-xiaoxiao-iris 已提交
1026
    dmInstance.on('uiStateChange', (data) => {
@
@shi-xiaoxiao-iris 已提交
1027 1028
    console.log("uiStateChange executed, dialog closed" + JSON.stringify(data))
    var tmpStr = JSON.parse(data.param)
1029 1030
    var isShow = tmpStr.verifyFailed
    console.log("uiStateChange executed, dialog closed" + isShow)
@
@shi-xiaoxiao-iris 已提交
1031 1032 1033 1034 1035 1036
  });
  } catch (err) {
    console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

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

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

1041 1042 1043
取消ui状态变更回调。

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

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

@
@shi-xiaoxiao-iris 已提交
1047
**参数:**
@
@shi-xiaoxiao-iris 已提交
1048

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

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

  ```js
  try {
@
@shi-xiaoxiao-iris 已提交
1058
    dmInstance.off('uiStateChange');
@
@shi-xiaoxiao-iris 已提交
1059 1060 1061 1062 1063
  } catch (err) {
    console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
  }
  ```

Z
zengyawen 已提交
1064
### on('deviceStateChange')
Z
zengyawen 已提交
1065

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

Z
zengyawen 已提交
1068 1069
注册设备状态回调。

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

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

@
@shi-xiaoxiao-iris 已提交
1074
**参数:**
@
@shi-xiaoxiao-iris 已提交
1075

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

@
@shi-xiaoxiao-iris 已提交
1081
**示例:**
@
@shi-xiaoxiao-iris 已提交
1082

1083
  ```js
1084 1085 1086 1087 1088
  try {
    dmInstance.on('deviceStateChange', (data) => {
      console.info("deviceStateChange on:" + JSON.stringify(data));
    });
  } catch (err) {
1089
    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
1090
  }
Z
zengyawen 已提交
1091
  ```
Z
zengyawen 已提交
1092

Z
zengyawen 已提交
1093
### off('deviceStateChange')
Z
zengyawen 已提交
1094

1095
off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void
Z
zengyawen 已提交
1096 1097 1098

取消注册设备状态回调。

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

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

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

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

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

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

1122 1123
### on('deviceFound')

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

注册发现设备回调监听。

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

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

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

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

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

1141
  ```js
1142 1143 1144 1145 1146
  try {
    dmInstance.on('deviceFound', (data) => {
      console.info("deviceFound:" + JSON.stringify(data));
    });
  } catch (err) {
1147
    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
1148
  }
1149 1150 1151 1152
  ```

### off('deviceFound')

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

取消注册设备发现回调。

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

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

@
@shi-xiaoxiao-iris 已提交
1161
**参数:**
@
@shi-xiaoxiao-iris 已提交
1162

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

@
@shi-xiaoxiao-iris 已提交
1168
**示例:**
@
@shi-xiaoxiao-iris 已提交
1169

1170
  ```js
1171 1172 1173 1174 1175
  try {
    dmInstance.off('deviceFound', (data) => {
      console.info('deviceFound' + JSON.stringify(data));
    });
  } catch (err) {
1176
    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
1177
  }
1178 1179 1180 1181
  ```

### on('discoverFail')

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
1190
**参数:**
@
@shi-xiaoxiao-iris 已提交
1191

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

@
@shi-xiaoxiao-iris 已提交
1197
**示例:**
@
@shi-xiaoxiao-iris 已提交
1198

1199
  ```js
1200 1201
  try {
    dmInstance.on('discoverFail', (data) => {
1202
        console.info("discoverFail on:" + JSON.stringify(data));
1203
    });
1204
  } catch (err) {
1205
    console.error("discoverFail errCode:" + err.code + ",errMessage:" + err.message);
1206
  }
1207 1208 1209 1210
  ```

### off('discoverFail')

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
1219
**参数:**
@
@shi-xiaoxiao-iris 已提交
1220

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

@
@shi-xiaoxiao-iris 已提交
1226
**示例:**
@
@shi-xiaoxiao-iris 已提交
1227

1228
  ```js
1229 1230 1231 1232 1233
  try {
    dmInstance.off('discoverFail', (data) => {
      console.info('discoverFail' + JSON.stringify(data));
    });
  } catch (err) {
1234
    console.error("discoverFail errCode:" + err.code + ",errMessage:" + err.message);
1235
  }
1236 1237
  ```

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

1240
on(type: 'publishSuccess', callback: Callback&lt;{ publishId: number }&gt;): void
S
summer8999 已提交
1241 1242 1243

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

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

S
summer8999 已提交
1246 1247
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1248
**参数:**
@
@shi-xiaoxiao-iris 已提交
1249

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

@
@shi-xiaoxiao-iris 已提交
1255

@
@shi-xiaoxiao-iris 已提交
1256
**示例:**
@
@shi-xiaoxiao-iris 已提交
1257

S
summer8999 已提交
1258
  ```js
1259 1260 1261 1262 1263
  try {
    dmInstance.on('publishSuccess', (data) => {
      console.info("publishSuccess:" + JSON.stringify(data));
    });
  } catch (err) {
1264
    console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message);
1265
  }
S
summer8999 已提交
1266 1267
  ```

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

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

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

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

S
summer8999 已提交
1276 1277
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1278
**参数:**
@
@shi-xiaoxiao-iris 已提交
1279

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

@
@shi-xiaoxiao-iris 已提交
1285
**示例:**
@
@shi-xiaoxiao-iris 已提交
1286

S
summer8999 已提交
1287
  ```js
1288 1289 1290 1291 1292
  try {
    dmInstance.off('publishSuccess', (data) => {
      console.info('publishSuccess' + JSON.stringify(data));
    });
  } catch (err) {
1293
    console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message);
1294
  }
S
summer8999 已提交
1295 1296
  ```

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

1299
on(type: 'publishFail', callback: Callback&lt;{ publishId: number, reason: number }&gt;): void
S
summer8999 已提交
1300 1301 1302

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

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

S
summer8999 已提交
1305 1306
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1307
**参数:**
@
@shi-xiaoxiao-iris 已提交
1308

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

@
@shi-xiaoxiao-iris 已提交
1314
**示例:**
@
@shi-xiaoxiao-iris 已提交
1315

S
summer8999 已提交
1316
  ```js
1317 1318
  try {
    dmInstance.on('publishFail', (data) => {
1319
      console.info("publishFail on:" + JSON.stringify(data));
1320 1321
    });
  } catch (err) {
1322
    console.error("publishFail errCode:" + err.code + ",errMessage:" + err.message);
1323
  }
S
summer8999 已提交
1324 1325
  ```

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

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

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

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

S
summer8999 已提交
1334 1335
**系统能力**:SystemCapability.DistributedHardware.DeviceManager

@
@shi-xiaoxiao-iris 已提交
1336
**参数:**
@
@shi-xiaoxiao-iris 已提交
1337

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

@
@shi-xiaoxiao-iris 已提交
1343
**示例:**
@
@shi-xiaoxiao-iris 已提交
1344

S
summer8999 已提交
1345
  ```js
1346 1347 1348 1349 1350
  try {
    dmInstance.off('publishFail', (data) => {
      console.info('publishFail' + JSON.stringify(data));
    });
  } catch (err) {
1351
    console.error("publishFail errCode:" + err.code + ",errMessage:" + err.message);
1352
  }
S
summer8999 已提交
1353
  ```
1354

Z
zengyawen 已提交
1355 1356 1357
### on('serviceDie')

on(type: 'serviceDie', callback: () =&gt; void): void
Z
zengyawen 已提交
1358 1359 1360

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

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

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

@
@shi-xiaoxiao-iris 已提交
1365
**参数:**
@
@shi-xiaoxiao-iris 已提交
1366

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

@
@shi-xiaoxiao-iris 已提交
1372
**示例:**
@
@shi-xiaoxiao-iris 已提交
1373

1374
  ```js
1375 1376 1377 1378 1379
  try {
    dmInstance.on("serviceDie", () => {
      console.info("serviceDie on");
    });
  } catch (err) {
1380
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1381
  }
Z
zengyawen 已提交
1382
  ```
Z
zengyawen 已提交
1383

Z
zengyawen 已提交
1384 1385 1386 1387 1388
### off('serviceDie')

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

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

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

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

@
@shi-xiaoxiao-iris 已提交
1394
**参数:**
@
@shi-xiaoxiao-iris 已提交
1395

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

@
@shi-xiaoxiao-iris 已提交
1401
**示例:**
@
@shi-xiaoxiao-iris 已提交
1402

1403
  ```js
1404 1405 1406 1407 1408
  try {
    dmInstance.off("serviceDie", () => {
      console.info("serviceDie off");
    });
  } catch (err) {
1409
    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1410
  }
1411
  ```