• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.distributedHardware.deviceManager (设备管理)(系统接口)
2
3本模块能力已更新至新模块。建议使用新模块的接口进行开发,参见[@ohos.distributedDeviceManager](js-apis-distributedDeviceManager.md)。
4
5本模块提供分布式设备管理能力。
6
7系统应用可调用接口实现如下功能:
8
9- 注册和解除注册设备上下线变化监听。
10- 发现周边不可信设备。
11- 认证和取消认证设备。
12- 查询可信设备列表。
13- 查询本地设备信息,包括设备名称,设备类型和设备标识。
14- 发布设备发现。
15
16> **说明:**
17>
18> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
19> - 本模块为系统接口,三方应用不支持调用。
20
21
22## 导入模块
23
24```ts
25import deviceManager from '@ohos.distributedHardware.deviceManager';
26```
27
28
29## deviceManager.createDeviceManager
30
31createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void;
32
33创建一个设备管理器实例。
34
35> 从API version 11 开始废弃。建议使用[deviceManager.createDeviceManager](js-apis-distributedDeviceManager.md#devicemanagercreatedevicemanager)替代。
36
37**系统能力**:SystemCapability.DistributedHardware.DeviceManager
38
39**错误码:**
40
41以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
42
43| 错误码ID | 错误信息                                                        |
44| -------- | --------------------------------------------------------------- |
45| 202 | Permission verification failed. A non-system application calls a system API. |
46| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
47
48**参数:**
49
50| 参数名     | 类型                                                 | 必填 | 说明                                                        |
51| ---------- | ---------------------------------------------------- | ---- | ----------------------------------------------------------- |
52| bundleName | string                                               | 是   | 指示应用程序的Bundle名称。长度范围1~255字符。                                  |
53| callback   | AsyncCallback<[DeviceManager](#devicemanager)> | 是   | DeviceManager实例创建时调用的回调,返回设备管理器对象实例。 |
54
55**示例:**
56
57  ```ts
58  import deviceManager from '@ohos.distributedHardware.deviceManager';
59  import { BusinessError } from '@ohos.base';
60
61  let dmInstance: deviceManager.DeviceManager | null = null;
62  try {
63    deviceManager.createDeviceManager("ohos.samples.jshelloworld", (err: BusinessError, data: deviceManager.DeviceManager) => {
64      if (err) {
65        console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
66        return;
67      }
68      console.info("createDeviceManager success");
69      dmInstance = data;
70    });
71  } catch(err) {
72    let e: BusinessError = err as BusinessError;
73    console.error("createDeviceManager errCode:" + e.code + ",errMessage:" + e.message);
74  }
75  ```
76
77## DeviceInfo
78
79设备信息。
80
81> 从API version 11 开始废弃。建议使用[DeviceBasicInfo](js-apis-distributedDeviceManager.md#devicebasicinfo)替代。
82
83**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
84
85| 名称                     | 类型                        | 必填   | 说明       |
86| ---------------------- | ------------------------- | ---- | -------- |
87| deviceId               | string                    | 是    | 设备的唯一标识。 |
88| deviceName             | string                    | 是    | 设备名称。    |
89| deviceType             | [DeviceType](#devicetype) | 是    | 设备类型。    |
90| networkId<sup>8+</sup> | string                    | 是    | 设备网络标识。  |
91| range<sup>9+</sup>     | number                    | 是    | 发现设备的距离。  |
92| authForm<sup>10+</sup> | [AuthForm](#authform10)     | 是    | 设备认证类型。  |
93
94## DeviceType
95
96表示设备类型的枚举类。
97
98> 从API version 11 开始废弃。无替代接口。
99
100**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
101
102| 名称           | 值  | 说明   |
103| ------------ | ---- | ---- |
104| SPEAKER      | 0x0A | 智能音箱。 |
105| PHONE        | 0x0E | 手机。   |
106| TABLET       | 0x11 | 平板。   |
107| WEARABLE     | 0x6D | 智能穿戴。 |
108| TV           | 0x9C | 智慧屏。  |
109| CAR          | 0x83 | 车。    |
110| UNKNOWN_TYPE | 0    | 未知设备。 |
111
112## AuthForm<sup>10+</sup>
113
114表示设备认证类型的枚举类。
115
116> 从API version 11 开始废弃。无替代接口。
117
118**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
119
120| 名称                 | 值  | 说明             |
121| ------------------- | ---- | --------------- |
122| INVALID_TYPE        | -1   | 设备没有认证。 |
123| PEER_TO_PEER        | 0    | 无账号设备点对点认证。   |
124| IDENTICAL_ACCOUNT   | 1    | 设备同账号认证。   |
125| ACROSS_ACCOUNT      | 2    | 设备跨账号认证。 |
126
127## DeviceStateChangeAction
128
129表示设备状态变化的枚举。
130
131> 从API version 11 开始废弃。建议使用[DeviceStateChange](js-apis-distributedDeviceManager.md#devicestatechange)替代。
132
133**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
134
135| 名称      | 值  | 说明              |
136| ------- | ---- | --------------- |
137| ONLINE  | 0    | 设备物理上线状态。           |
138| READY   | 1    | 设备可用状态,表示设备间信息已在分布式数据中同步完成, 可以运行分布式业务。 |
139| OFFLINE | 2    | 设备物理下线状态。           |
140| CHANGE  | 3    | 设备信息更改。         |
141
142## SubscribeInfo
143
144发现信息。
145
146> 从API version 11 开始废弃。无替代接口。
147
148**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
149
150| 名称            | 类型                                | 必填   | 说明                |
151| ------------- | --------------------------------- | ---- | ----------------- |
152| subscribeId   | number                            | 是    | 发现标识,用于标识不同的发现周期。 取值范围1~65535。|
153| mode          | [DiscoverMode ](#discovermode)    | 是    | 发现模式。             |
154| medium        | [ExchangeMedium](#exchangemedium) | 是    | 发现类型。             |
155| freq          | [ExchangeFreq](#exchangefreq)     | 是    | 发现频率。             |
156| isSameAccount | boolean                           | 否    | 是否同账号,true表示同账号,false表示异账号。            |
157| isWakeRemote  | boolean                           | 否    | 是否唤醒设备,true表示唤醒,false表示不用唤醒。           |
158| capability    | [SubscribeCap](#subscribecap)     | 是    | 发现能力。             |
159
160## DiscoverMode
161
162表示发现模式的枚举。
163
164> 从API version 11 开始废弃。无替代接口。
165
166**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
167
168| 名称                    | 值  | 说明    |
169| --------------------- | ---- | ----- |
170| DISCOVER_MODE_PASSIVE | 0x55 | 被动模式。 |
171| DISCOVER_MODE_ACTIVE  | 0xAA | 主动模式。 |
172
173
174## ExchangeMedium
175
176表示发现类型的枚举。
177
178> 从API version 11 开始废弃。无替代接口。
179
180**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
181
182| 名称   | 值  | 说明        |
183| ---- | ---- | --------- |
184| AUTO | 0    | 自动发现类型。   |
185| BLE  | 1    | 蓝牙发现类型。   |
186| COAP | 2    | WiFi发现类型。 |
187| USB  | 3    | USB发现类型。  |
188
189## ExchangeFreq
190
191表示发现频率的枚举。
192
193> 从API version 11 开始废弃。无替代接口。
194
195**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
196
197| 名称         | 值  | 说明    |
198| ---------- | ---- | ----- |
199| LOW        | 0    | 低频率。  |
200| MID        | 1    | 中频率。  |
201| HIGH       | 2    | 高频率。  |
202| SUPER_HIGH | 3    | 超高频率。 |
203
204
205## SubscribeCap
206
207表示发现能力的枚举。
208
209> 从API version 11 开始废弃。无替代接口。
210
211**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
212
213| 名称                        | 值  | 说明             |
214| ------------------------- | ---- | -------------- |
215| SUBSCRIBE_CAPABILITY_DDMP | 0    | DDMP能力,后续会被废弃。 |
216| SUBSCRIBE_CAPABILITY_OSD  | 1    | OSD能力。         |
217
218
219## AuthParam
220
221认证参数。
222
223> 从API version 11 开始废弃。无替代接口。
224
225**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
226
227| 名称        | 类型                   | 必填   | 说明         |
228| --------- | -------------------- | ---- | ---------- |
229| authType  | number               | 是    | 认证类型。      |
230| extraInfo | {[key:string]&nbsp;:&nbsp;any} | 否    | 认证参数可扩展字段。可选,默认为undefined。 |
231
232## AuthInfo
233
234认证信息。
235
236> 从API version 11 开始废弃。无替代接口。
237
238**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
239
240| 名称        | 类型                   | 必填   | 说明         |
241| --------- | -------------------- | ---- | ---------- |
242| authType  | number               | 是    | 认证类型。      |
243| token     | number               | 是    | 认证Token。   |
244| extraInfo | {[key:string]&nbsp;:&nbsp;any} | 否    | 认证信息可扩展字段。可选,默认为undefined。 |
245
246## PublishInfo<sup>9+</sup>
247
248发布设备参数
249
250> 从API version 11 开始废弃。无替代接口。
251
252**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
253
254| 名称          | 类型                              | 必填   | 说明                |
255| ------------- | --------------------------------- | ---- | ----------------- |
256| publishId     | number                            | 是    | 发布设备标识,用于标识不同的发布周期。 |
257| mode          | [DiscoverMode ](#discovermode)    | 是    | 发现模式。             |
258| freq          | [ExchangeFreq](#exchangefreq)     | 是    | 发现频率。             |
259| ranging       | boolean                           | 是    | 发布的设备是否支持测距能力,true表示支持测距能力,false表示不支持测距能力。             |
260
261## DeviceManager
262
263设备管理实例,用于获取可信设备和本地设备的相关信息。在调用DeviceManager的方法前,需要先通过createDeviceManager构建一个DeviceManager实例dmInstance。
264
265### release
266
267release(): void;
268
269设备管理实例不再使用后,通过该方法释放DeviceManager实例。
270
271> 从API version 11 开始废弃。建议使用[deviceManager.releaseDeviceManager](js-apis-distributedDeviceManager.md#devicemanagerreleasedevicemanager)替代。
272
273**需要权限**:ohos.permission.ACCESS_SERVICE_DM
274
275**系统能力**:SystemCapability.DistributedHardware.DeviceManager
276
277**错误码:**
278
279以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。
280
281| 错误码ID | 错误信息                                                        |
282| -------- | --------------------------------------------------------------- |
283| 201 | Permission verification failed. The application does not have the permission required to call the API.                                            |
284| 202 | Permission verification failed. A non-system application calls a system API.                              |
285| 11600101 | Failed to execute the function.                                 |
286
287**示例:**
288
289示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
290  ```ts
291  import { BusinessError } from '@ohos.base';
292
293  try {
294    dmInstance.release();
295  } catch (err) {
296    let e: BusinessError = err as BusinessError;
297    console.error("release errCode:" + e.code + ",errMessage:" + e.message);
298  }
299  ```
300
301### getTrustedDeviceListSync
302
303getTrustedDeviceListSync(): Array&lt;DeviceInfo&gt;;
304
305同步获取所有可信设备列表。
306
307> 从API version 11 开始废弃。建议使用[getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync)替代。
308
309**需要权限**:ohos.permission.ACCESS_SERVICE_DM
310
311**系统能力**:SystemCapability.DistributedHardware.DeviceManager
312
313**返回值:**
314
315  | 名称                                     | 说明        |
316  | -------------------------------------- | --------- |
317  | Array&lt;[DeviceInfo](#deviceinfo)&gt; | 返回可信设备列表。 |
318
319**错误码:**
320
321以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。
322
323| 错误码ID | 错误信息                                                        |
324| -------- | --------------------------------------------------------------- |
325| 201 | Permission verification failed. The application does not have the permission required to call the API.                                            |
326| 202 | Permission verification failed. A non-system application calls a system API.                              |
327| 11600101 | Failed to execute the function.                                 |
328
329**示例:**
330
331示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
332  ```ts
333  import deviceManager from '@ohos.distributedHardware.deviceManager';
334  import { BusinessError } from '@ohos.base';
335
336  try {
337    let deviceInfoList: Array<deviceManager.DeviceInfo> = dmInstance.getTrustedDeviceListSync();
338  } catch (err) {
339    let e: BusinessError = err as BusinessError;
340    console.error("getTrustedDeviceListSync errCode:" + e.code + ",errMessage:" + e.message);
341  }
342  ```
343
344### getTrustedDeviceListSync<sup>10+</sup>
345
346getTrustedDeviceListSync(isRefresh: boolean): Array&lt;DeviceInfo&gt;;
347
348打开软总线系统端的心跳模式,让周围处于下线状态的可信设备快速上线,同时刷新已上线的可信设备列表。
349
350> 从API version 11 开始废弃。无替代接口。
351
352**需要权限**:ohos.permission.ACCESS_SERVICE_DM
353
354**系统能力**:SystemCapability.DistributedHardware.DeviceManager
355
356**参数:**
357
358| 参数名        | 类型                               | 必填 | 说明                                |
359| ------------- | --------------------------------- | ---- | ---------------------------------- |
360|   isRefresh   | boolean                           | 是   | 是否打开心跳模式,刷新可信列表,true表示打开心跳模式,false表示关闭心跳模式。      |
361
362**返回值:**
363
364| 名称                                     | 说明            |
365| -------------------------------------- | ---------------- |
366| Array&lt;[DeviceInfo](#deviceinfo)&gt; | 返回可信设备列表。 |
367
368**错误码:**
369
370以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。
371
372| 错误码ID | 错误信息                                                         |
373| -------- | --------------------------------------------------------------- |
374| 201 | Permission verification failed. The application does not have the permission required to call the API.                                            |
375| 202 | Permission verification failed. A non-system application calls a system API.                              |
376| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. |
377| 11600101 | Failed to execute the function.                                 |
378
379**示例:**
380
381示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
382  ```ts
383  import deviceManager from '@ohos.distributedHardware.deviceManager';
384  import { BusinessError } from '@ohos.base';
385
386  try {
387    let deviceInfoList: Array<deviceManager.DeviceInfo> = dmInstance.getTrustedDeviceListSync(true);
388  } catch (err) {
389    let e: BusinessError = err as BusinessError;
390    console.error("getTrustedDeviceListSync errCode:" + e.code + ",errMessage:" + e.message);
391  }
392  ```
393
394### getTrustedDeviceList<sup>8+</sup>
395
396getTrustedDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceInfo&gt;&gt;): void;
397
398获取所有可信设备列表。使用callback异步回调。
399
400> 从API version 11 开始废弃。建议使用[getAvailableDeviceList](js-apis-distributedDeviceManager.md#getavailabledevicelist)替代。
401
402**需要权限**:ohos.permission.ACCESS_SERVICE_DM
403
404**系统能力**:SystemCapability.DistributedHardware.DeviceManager
405
406**参数:**
407
408  | 参数名       | 类型                                     | 必填   | 说明                    |
409  | -------- | ---------------------------------------- | ---- | --------------------- |
410  | callback | AsyncCallback&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | 是    | 获取所有可信设备列表的回调,返回设备信息。 |
411
412**错误码:**
413
414以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
415
416| 错误码ID | 错误信息                                                         |
417| -------- | --------------------------------------------------------------- |
418| 202 | Permission verification failed. A non-system application calls a system API.                              |
419| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. |
420
421**示例:**
422
423示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
424  ```ts
425  import deviceManager from '@ohos.distributedHardware.deviceManager';
426  import { BusinessError } from '@ohos.base';
427
428  try {
429    dmInstance.getTrustedDeviceList((err: BusinessError, data: Array<deviceManager.DeviceInfo>) => {
430      if (err) {
431        console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
432        return;
433      }
434      console.log('get trusted device info: ' + JSON.stringify(data));
435    });
436  } catch (err) {
437    let e: BusinessError = err as BusinessError;
438    console.error("getTrustedDeviceList errCode:" + e.code + ",errMessage:" + e.message);
439  }
440  ```
441
442### getTrustedDeviceList<sup>8+</sup>
443
444getTrustedDeviceList(): Promise&lt;Array&lt;DeviceInfo&gt;&gt;;
445
446获取所有可信设备列表。使用Promise异步回调。
447
448> 从API version 11 开始废弃。建议使用[getAvailableDeviceList](js-apis-distributedDeviceManager.md#getavailabledevicelist-1)替代。
449
450**需要权限**:ohos.permission.ACCESS_SERVICE_DM
451
452**系统能力**:SystemCapability.DistributedHardware.DeviceManager
453
454**返回值:**
455
456  | 类型                                       | 说明                    |
457  | ---------------------------------------- | --------------------- |
458  | Promise&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | Promise实例,用于获取异步返回结果。 |
459
460**错误码:**
461
462以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
463
464| 错误码ID | 错误信息                                                         |
465| -------- | --------------------------------------------------------------- |
466| 202 | Permission verification failed. A non-system application calls a system API.                              |
467
468**示例:**
469
470示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
471  ```ts
472  import deviceManager from '@ohos.distributedHardware.deviceManager';
473  import { BusinessError } from '@ohos.base';
474
475  dmInstance.getTrustedDeviceList().then((data: Array<deviceManager.DeviceInfo>) => {
476    console.log('get trusted device info: ' + JSON.stringify(data));
477    }).catch((err: BusinessError) => {
478      console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
479  });
480  ```
481
482### getLocalDeviceInfoSync<sup>8+</sup>
483
484getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo);
485
486同步获取本地设备信息。
487
488> 从API version 11 开始废弃。建议使用[getLocalDeviceNetworkId](js-apis-distributedDeviceManager.md#getlocaldevicenetworkid),[getLocalDeviceName](js-apis-distributedDeviceManager.md#getlocaldevicename),[getLocalDeviceType](js-apis-distributedDeviceManager.md#getlocaldevicetype),[getLocalDeviceId](js-apis-distributedDeviceManager.md#getlocaldeviceid)替代。
489
490**需要权限**:ohos.permission.ACCESS_SERVICE_DM
491
492**系统能力**:SystemCapability.DistributedHardware.DeviceManager
493
494**返回值:**
495
496  | 名称                      | 说明              |
497  | ------------------------- | ---------------- |
498  | [DeviceInfo](#deviceinfo) | 返回本地设备列表。 |
499
500**错误码:**
501
502以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。
503
504| 错误码ID | 错误信息                                                        |
505| -------- | --------------------------------------------------------------- |
506| 201 | Permission verification failed. The application does not have the permission required to call the API.                                            |
507| 202 | Permission verification failed. A non-system application calls a system API.                              |
508| 11600101 | Failed to execute the function.                                 |
509
510**示例:**
511
512示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
513  ```ts
514  import deviceManager from '@ohos.distributedHardware.deviceManager';
515  import { BusinessError } from '@ohos.base';
516
517  try {
518    let deviceInfo: deviceManager.DeviceInfo = dmInstance.getLocalDeviceInfoSync();
519  } catch (err) {
520    let e: BusinessError = err as BusinessError;
521    console.error("getLocalDeviceInfoSync errCode:" + e.code + ",errMessage:" + e.message);
522  }
523  ```
524
525### getLocalDeviceInfo<sup>8+</sup>
526
527getLocalDeviceInfo(callback:AsyncCallback&lt;DeviceInfo&gt;): void;
528
529获取本地设备信息。使用callback异步回调。
530
531> 从API version 11 开始废弃。建议使用[getLocalDeviceNetworkId](js-apis-distributedDeviceManager.md#getlocaldevicenetworkid),[getLocalDeviceName](js-apis-distributedDeviceManager.md#getlocaldevicename),[getLocalDeviceType](js-apis-distributedDeviceManager.md#getlocaldevicetype),[getLocalDeviceId](js-apis-distributedDeviceManager.md#getlocaldeviceid)替代。
532
533**需要权限**:ohos.permission.ACCESS_SERVICE_DM
534
535**系统能力**:SystemCapability.DistributedHardware.DeviceManager
536
537**参数:**
538
539  | 参数名       | 类型                                     | 必填   | 说明        |
540  | -------- | ---------------------------------------- | ---- | --------- |
541  | callback | AsyncCallback&lt;[DeviceInfo](#deviceinfo)&gt; | 是    | 获取本地设备信息。 |
542
543**错误码:**
544
545以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
546
547| 错误码ID | 错误信息                                                         |
548| -------- | --------------------------------------------------------------- |
549| 202 | Permission verification failed. A non-system application calls a system API.                              |
550| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. |
551
552**示例:**
553
554示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
555  ```ts
556  import deviceManager from '@ohos.distributedHardware.deviceManager';
557  import { BusinessError } from '@ohos.base';
558
559
560  try {
561    dmInstance.getLocalDeviceInfo((err: BusinessError, data: deviceManager.DeviceInfo) => {
562      if (err) {
563        console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
564        return;
565      }
566      console.log('get local device info: ' + JSON.stringify(data));
567    });
568  } catch (err) {
569    let e: BusinessError = err as BusinessError;
570    console.error("getLocalDeviceInfo errCode:" + e.code + ",errMessage:" + e.message);
571  }
572  ```
573
574### getLocalDeviceInfo<sup>8+</sup>
575
576getLocalDeviceInfo(): Promise&lt;DeviceInfo&gt;;
577
578获取本地设备信息。使用Promise异步回调。
579
580> 从API version 11 开始废弃。建议使用[getLocalDeviceNetworkId](js-apis-distributedDeviceManager.md#getlocaldevicenetworkid),[getLocalDeviceName](js-apis-distributedDeviceManager.md#getlocaldevicename),[getLocalDeviceType](js-apis-distributedDeviceManager.md#getlocaldevicetype),[getLocalDeviceId](js-apis-distributedDeviceManager.md#getlocaldeviceid)替代。
581
582**需要权限**:ohos.permission.ACCESS_SERVICE_DM
583
584**系统能力**:SystemCapability.DistributedHardware.DeviceManager
585
586**返回值:**
587
588  | 类型                                       | 说明                    |
589  | ---------------------------------------- | --------------------- |
590  | Promise&lt;[DeviceInfo](#deviceinfo)&gt; | Promise实例,用于获取异步返回结果。 |
591
592**错误码:**
593
594以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
595
596| 错误码ID | 错误信息                                                         |
597| -------- | --------------------------------------------------------------- |
598| 202 | Permission verification failed. A non-system application calls a system API.                              |
599
600**示例:**
601
602示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
603  ```ts
604  import deviceManager from '@ohos.distributedHardware.deviceManager';
605  import { BusinessError } from '@ohos.base';
606
607  dmInstance.getLocalDeviceInfo().then((data: deviceManager.DeviceInfo) => {
608    console.log('get local device info: ' + JSON.stringify(data));
609  }).catch((err: BusinessError) => {
610    console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
611  });
612  ```
613
614### getDeviceInfo<sup>10+</sup>
615
616getDeviceInfo(networkId: string, callback:AsyncCallback&lt;DeviceInfo&gt;): void;
617
618通过指定设备的网络标识获取该设备的信息。使用callback异步回调。
619
620> 从API version 11 开始废弃。建议使用[getDeviceName](js-apis-distributedDeviceManager.md#getdevicename),[getDeviceType](js-apis-distributedDeviceManager.md#getdevicetype)替代。
621
622**需要权限**:ohos.permission.ACCESS_SERVICE_DM
623
624**系统能力**:SystemCapability.DistributedHardware.DeviceManager
625
626**参数:**
627
628  | 参数名       | 类型                                     | 必填   | 说明        |
629  | -------- | ---------------------------------------- | ---- | --------- |
630  | networkId| string                                   | 是   | 设备的网络标识。长度范围1~255字符。 |
631  | callback | AsyncCallback&lt;[DeviceInfo](#deviceinfo)&gt; | 是    | 获取指定设备信息。 |
632
633**错误码:**
634
635以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
636
637| 错误码ID | 错误信息                                                         |
638| -------- | --------------------------------------------------------------- |
639| 202 | Permission verification failed. A non-system application calls a system API.                              |
640| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified networkId is greater than 255. |
641
642**示例:**
643
644示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
645  ```ts
646  import deviceManager from '@ohos.distributedHardware.deviceManager';
647  import { BusinessError } from '@ohos.base';
648
649  try {
650    // 设备网络标识,可以从可信设备列表中获取
651    let networkId = "xxxxxxx";
652    dmInstance.getDeviceInfo(networkId, (err: BusinessError, data: deviceManager.DeviceInfo) => {
653      if (err) {
654        console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
655        return;
656      }
657      console.log('get device info: ' + JSON.stringify(data));
658    });
659  } catch (err) {
660    let e: BusinessError = err as BusinessError;
661    console.error("getDeviceInfo errCode:" + e.code + ",errMessage:" + e.message);
662  }
663  ```
664
665### getDeviceInfo<sup>10+</sup>
666
667getDeviceInfo(networkId: string): Promise&lt;DeviceInfo&gt;;
668
669通过指定设备的网络标识获取该设备的信息。使用Promise异步回调。
670
671> 从API version 11 开始废弃。建议使用[getDeviceName](js-apis-distributedDeviceManager.md#getdevicename),[getDeviceType](js-apis-distributedDeviceManager.md#getdevicetype)替代。
672
673**需要权限**:ohos.permission.ACCESS_SERVICE_DM
674
675**系统能力**:SystemCapability.DistributedHardware.DeviceManager
676
677**参数:**
678
679  | 参数名   | 类型                                     | 必填 | 说明        |
680  | -------- | ---------------------------------------- | ---- | --------- |
681  | networkId| string                                   | 是   | 设备的网络标识。长度范围1~255字符。 |
682
683**返回值:**
684
685  | 类型                                       | 说明                    |
686  | ---------------------------------------- | --------------------- |
687  | Promise&lt;[DeviceInfo](#deviceinfo)&gt; | Promise实例,用于获取异步返回结果。 |
688
689**错误码:**
690
691以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
692
693| 错误码ID | 错误信息                                                         |
694| -------- | --------------------------------------------------------------- |
695| 202 | Permission verification failed. A non-system application calls a system API.                              |
696| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified networkId is greater than 255. |
697
698**示例:**
699
700示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
701  ```ts
702  import deviceManager from '@ohos.distributedHardware.deviceManager';
703  import { BusinessError } from '@ohos.base';
704
705  // 设备网络标识,可以从可信设备列表中获取
706  let networkId = "xxxxxxx";
707  dmInstance.getDeviceInfo(networkId).then((data: deviceManager.DeviceInfo) => {
708    console.log('get device info: ' + JSON.stringify(data));
709  }).catch((err: BusinessError) => {
710    console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
711  });
712  ```
713
714### startDeviceDiscovery<sup>8+</sup>
715
716startDeviceDiscovery(subscribeInfo: SubscribeInfo): void;
717
718发现周边设备。发现状态持续两分钟,超过两分钟,会停止发现,最大发现数量99个。
719
720> 从API version 11 开始废弃。建议使用[startDiscovering](js-apis-distributedDeviceManager.md#startdiscovering)替代。
721
722**需要权限**:ohos.permission.ACCESS_SERVICE_DM
723
724**系统能力**:SystemCapability.DistributedHardware.DeviceManager
725
726**参数:**
727
728  | 参数名            | 类型                       | 必填 | 说明    |
729  | ------------- | ------------------------------- | ---- | ----- |
730  | subscribeInfo | [SubscribeInfo](#subscribeinfo) | 是   | 发现信息。|
731
732**错误码:**
733
734以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。
735
736| 错误码ID | 错误信息                                                        |
737| -------- | --------------------------------------------------------------- |
738| 201 | Permission verification failed. The application does not have the permission required to call the API.                                            |
739| 202 | Permission verification failed. A non-system application calls a system API.                              |
740| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified networkId is greater than 255. |
741| 11600101 | Failed to execute the function.                                 |
742| 11600104 | Discovery unavailable.                                              |
743
744**示例:**
745
746示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
747  ```ts
748  import { BusinessError } from '@ohos.base';
749
750  interface SubscribeInfo {
751    subscribeId: number;
752    mode: number;   // 主动模式
753    medium: number; // 自动发现类型,同时支持多种发现类型
754    freq: number;   // 高频率
755    isSameAccount: boolean;
756    isWakeRemote: boolean;
757    capability: number;
758  }
759
760  // 生成发现标识,随机数确保每次调用发现接口的标识不一致
761  let subscribeId = Math.floor(Math.random() * 10000 + 1000);
762  let subscribeInfo: SubscribeInfo = {
763    subscribeId: subscribeId,
764    mode: 0xAA, // 主动模式
765    medium: 0,  // 自动发现类型,同时支持多种发现类型
766    freq: 2,    // 高频率
767    isSameAccount: false,
768    isWakeRemote: false,
769    capability: 1
770  };
771  try {
772    dmInstance.startDeviceDiscovery(subscribeInfo); // 当有设备发现时,通过deviceFound回调通知给应用程序
773  } catch (err) {
774    let e: BusinessError = err as BusinessError;
775    console.error("startDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
776  }
777  ```
778
779### startDeviceDiscovery<sup>9+</sup>
780
781startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void;
782
783发现周边设备。发现状态持续两分钟,超过两分钟,会停止发现,最大发现数量99个。
784
785> 从API version 11 开始废弃。建议使用[startDiscovering](js-apis-distributedDeviceManager.md#startdiscovering)替代。
786
787**需要权限**:ohos.permission.ACCESS_SERVICE_DM
788
789**系统能力**:SystemCapability.DistributedHardware.DeviceManager
790
791**参数:**
792
793  | 参数名            | 类型                       | 必填   | 说明    |
794  | ------------- | ------------------------------- | ---- | -----  |
795  | subscribeInfo | [SubscribeInfo](#subscribeinfo) | 是   | 发现信息。 |
796  | filterOptions | string                          | 否   | 发现设备过滤信息。可选,默认为undefined,发现未上线设备。长度范围1~255字符。|
797
798**错误码:**
799
800以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。
801
802| 错误码ID | 错误信息                                                        |
803| -------- | --------------------------------------------------------------- |
804| 201 | Permission verification failed. The application does not have the permission required to call the API.                                            |
805| 202 | Permission verification failed. A non-system application calls a system API.                              |
806| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified networkId is greater than 255. |
807| 11600101 | Failed to execute the function.                                 |
808| 11600104 | Discovery unavailable.                                              |
809
810**示例:**
811
812示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
813  ```ts
814  import { BusinessError } from '@ohos.base';
815
816  interface Filters {
817    type: string;
818    value: number;
819  }
820
821  interface FilterOptions {
822    filter_op: string; // 可选, 默认"OR"
823    filters: Filters[];
824  }
825
826  interface SubscribeInfo {
827    subscribeId: number;
828    mode: number;   // 主动模式
829    medium: number; // 自动发现类型,同时支持多种发现类型
830    freq: number;   // 高频率
831    isSameAccount: boolean;
832    isWakeRemote: boolean;
833    capability: number;
834  }
835
836  // 生成发现标识,随机数确保每次调用发现接口的标识不一致
837  let subscribeId = Math.floor(Math.random() * 10000 + 1000);
838  let subscribeInfo: SubscribeInfo = {
839    subscribeId: subscribeId,
840    mode: 0xAA, // 主动模式
841    medium: 0,  // 自动发现类型,同时支持多种发现类型
842    freq: 2,    // 高频率
843    isSameAccount: false,
844    isWakeRemote: false,
845    capability: 1
846  };
847
848  let filters: Filters[] = [
849    {
850        type: "range",
851        value: 50 // 需过滤发现设备的距离,单位(cm)
852    }
853  ];
854
855  let filterOptions: FilterOptions = {
856    filter_op: "OR", // 可选, 默认"OR"
857    filters: filters
858  };
859  try {
860    dmInstance.startDeviceDiscovery(subscribeInfo, JSON.stringify(filterOptions)); // 当有设备发现时,通过deviceFound回调通知给应用程序
861  } catch (err) {
862    let e: BusinessError = err as BusinessError;
863    console.error("startDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
864  }
865  ```
866
867### stopDeviceDiscovery
868
869stopDeviceDiscovery(subscribeId: number): void;
870
871停止发现周边设备。
872
873> 从API version 11 开始废弃。建议使用[stopDiscovering](js-apis-distributedDeviceManager.md#stopdiscovering)替代。
874
875**需要权限**:ohos.permission.ACCESS_SERVICE_DM
876
877**系统能力**:SystemCapability.DistributedHardware.DeviceManager
878
879**参数:**
880
881  | 参数名          | 类型   | 必填   | 说明    |
882  | ----------- | ------ | ---- | ----- |
883  | subscribeId | number | 是    | 发现标识。取值范围为1~65535。 |
884
885**错误码:**
886
887以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。
888
889| 错误码ID | 错误信息                                                        |
890| -------- | --------------------------------------------------------------- |
891| 201 | Permission verification failed. The application does not have the permission required to call the API.                                            |
892| 202 | Permission verification failed. A non-system application calls a system API.                              |
893| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified networkId is greater than 255. |
894| 11600101 | Failed to execute the function.                                 |
895
896**示例:**
897
898示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
899  ```ts
900  import { BusinessError } from '@ohos.base';
901
902  try {
903    // stopDeviceDiscovery和startDeviceDiscovery需配对使用,入参需要和startDeviceDiscovery接口传入的subscribeId值相等
904    let subscribeId = 12345;
905    dmInstance.stopDeviceDiscovery(subscribeId);
906  } catch (err) {
907    let e: BusinessError = err as BusinessError;
908    console.error("stopDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
909  }
910  ```
911
912### publishDeviceDiscovery<sup>9+</sup>
913
914publishDeviceDiscovery(publishInfo: PublishInfo): void;
915
916发布设备发现。发布状态持续两分钟,超过两分钟会停止发布。
917
918> 从API version 11 开始废弃。无替代接口。
919
920**需要权限**:ohos.permission.ACCESS_SERVICE_DM
921
922**系统能力**:SystemCapability.DistributedHardware.DeviceManager
923
924**参数:**
925
926  | 参数名          | 类型                        | 必填 | 说明    |
927  | ------------- | ------------------------------- | ---- | ----- |
928  | publishInfo   | [PublishInfo](#publishinfo9)     | 是   | 发布设备发现信息。 |
929
930**错误码:**
931
932以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。
933
934| 错误码ID | 错误信息                                                        |
935| -------- | --------------------------------------------------------------- |
936| 201 | Permission verification failed. The application does not have the permission required to call the API.                                            |
937| 202 | Permission verification failed. A non-system application calls a system API.                              |
938| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. |
939| 11600101 | Failed to execute the function.                                 |
940| 11600105 | Publish unavailable.                                                |
941
942**示例:**
943
944示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
945  ```ts
946  import { BusinessError } from '@ohos.base';
947
948  interface PublishInfo {
949    publishId: number;
950    mode: number; // 主动模式
951    freq: number; // 高频率
952    ranging: boolean; // 支持发现时测距
953  };
954
955  // 生成发布标识,随机数确保每次调用发布接口的标识不一致
956  let publishId = Math.floor(Math.random() * 10000 + 1000);
957  let publishInfo: PublishInfo = {
958    publishId: publishId,
959    mode: 0xAA, // 主动模式
960    freq: 2,    // 高频率
961    ranging: true  // 支持发现时测距
962  };
963
964  try {
965    dmInstance.publishDeviceDiscovery(publishInfo); // 当有发布结果时,通过回调通知给应用程序
966  } catch (err) {
967    let e: BusinessError = err as BusinessError;
968    console.error("publishDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
969  }
970  ```
971
972### unPublishDeviceDiscovery<sup>9+</sup>
973
974unPublishDeviceDiscovery(publishId: number): void;
975
976停止发布设备发现。
977
978> 从API version 11 开始废弃。无替代接口。
979
980**需要权限**:ohos.permission.ACCESS_SERVICE_DM
981
982**系统能力**:SystemCapability.DistributedHardware.DeviceManager
983
984**参数:**
985
986  | 参数名        | 类型 | 必填 | 说明  |
987  | ----------- | -------- | ---- | ----- |
988  | publishId   | number   | 是   | 发布标识。 取值范围为1~2147483647。|
989
990**错误码:**
991
992以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。
993
994| 错误码ID | 错误信息                                                        |
995| -------- | --------------------------------------------------------------- |
996| 201 | Permission verification failed. The application does not have the permission required to call the API.                                            |
997| 202 | Permission verification failed. A non-system application calls a system API.                              |
998| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. |
999| 11600101 | Failed to execute the function.                                 |
1000
1001**示例:**
1002
1003示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1004  ```ts
1005  import { BusinessError } from '@ohos.base';
1006
1007  try {
1008    // unPublishDeviceDiscovery和publishDeviceDiscovery配对使用,入参需要和publishDeviceDiscovery接口传入的publishId值相等
1009    let publishId = 12345;
1010    dmInstance.unPublishDeviceDiscovery(publishId);
1011  } catch (err) {
1012    let e: BusinessError = err as BusinessError;
1013    console.error("unPublishDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
1014  }
1015  ```
1016
1017### authenticateDevice
1018
1019authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback&lt;{deviceId: string, pinToken ?: number}&gt;): void;
1020
1021认证设备。
1022
1023> 从API version 11 开始废弃。建议使用[bindTarget](js-apis-distributedDeviceManager.md#bindtarget)替代。
1024
1025**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1026
1027**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1028
1029**参数:**
1030
1031  | 参数名         | 类型                                     | 必填   | 说明      |
1032  | ---------- | ---------------------------------------- | ---- | ------- |
1033  | deviceInfo | [DeviceInfo](#deviceinfo)                | 是    | 设备信息。   |
1034  | authParam  | [AuthParam](#authparam)                  | 是    | 认证参数。   |
1035  | callback   | AsyncCallback&lt;{deviceId:&nbsp;string,&nbsp;pinToken&nbsp;?:&nbsp;number}&gt; | 是    | 认证结果回调。 |
1036
1037**错误码:**
1038
1039以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1040
1041| 错误码ID | 错误信息                                                        |
1042| -------- | --------------------------------------------------------------- |
1043| 202 | Permission verification failed. A non-system application calls a system API.                              |
1044| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. |
1045
1046**示例:**
1047
1048示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1049  ```ts
1050  import { BusinessError } from '@ohos.base';
1051
1052  class Data {
1053    deviceId: string = "";
1054    pinToken?: number = 0;
1055  }
1056
1057  interface DeviceInfo {
1058    deviceId: string;
1059    deviceName: string;
1060    deviceType: number;
1061    networkId: string;
1062    range: number;
1063  };
1064
1065  interface ExtraInfo {
1066    targetPkgName: string;
1067    appName: string;
1068    appDescription: string;
1069    business: string;
1070  }
1071
1072  interface AuthParam {
1073    authType: number; // 认证类型: 1 - 无账号PIN码认证
1074    extraInfo: ExtraInfo;
1075  }
1076
1077  // 认证的设备信息,可以从发现的结果中获取
1078  let deviceInfo: deviceManager.DeviceInfo = {
1079    deviceId: "XXXXXXXX",
1080    deviceName: "",
1081    deviceType: 0x0E,
1082    networkId: "xxxxxxx",
1083    range: 0,
1084    authForm: 0
1085  };
1086  let extraInfo: ExtraInfo = {
1087    targetPkgName: 'ohos.samples.xxx',
1088    appName: 'xxx',
1089    appDescription: 'xxx',
1090    business: '0'
1091  };
1092  let authParam: AuthParam = {
1093    authType: 1,// 认证类型: 1 - 无账号PIN码认证
1094    extraInfo: extraInfo
1095  };
1096
1097  try {
1098    dmInstance.authenticateDevice(deviceInfo, authParam, (err: BusinessError, data: Data) => {
1099      if (err) {
1100        console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
1101        return;
1102      }
1103      console.info("authenticateDevice result:" + JSON.stringify(data));
1104      let token = data.pinToken;
1105    });
1106  } catch (err) {
1107    let e: BusinessError = err as BusinessError;
1108    console.error("authenticateDevice errCode:" + e.code + ",errMessage:" + e.message);
1109  }
1110  ```
1111
1112### unAuthenticateDevice<sup>8+</sup>
1113
1114unAuthenticateDevice(deviceInfo: DeviceInfo): void;
1115
1116解除认证设备。
1117
1118> 从API version 11 开始废弃。建议使用[unbindTarget](js-apis-distributedDeviceManager.md#unbindtarget)替代。
1119
1120**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1121
1122**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1123
1124**参数:**
1125
1126  | 参数名         | 类型                      | 必填   | 说明    |
1127  | ---------- | ------------------------- | ---- | ----- |
1128  | deviceInfo | [DeviceInfo](#deviceinfo) | 是    | 设备信息。 |
1129
1130**错误码:**
1131
1132以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。
1133
1134| 错误码ID | 错误信息                                                        |
1135| -------- | --------------------------------------------------------------- |
1136| 201 | Permission verification failed. The application does not have the permission required to call the API.                                            |
1137| 202 | Permission verification failed. A non-system application calls a system API.                              |
1138| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. |
1139| 11600101 | Failed to execute the function.                                 |
1140
1141**示例:**
1142
1143示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1144  ```ts
1145  import { BusinessError } from '@ohos.base';
1146
1147  interface DeviceInfo {
1148    deviceId: string;
1149    deviceName: string;
1150    deviceType: number;
1151    networkId: string;
1152    range: number;
1153  }
1154
1155  try {
1156    let deviceInfo: deviceManager.DeviceInfo = {
1157      deviceId: "XXXXXXXX",
1158      deviceName: "",
1159      deviceType: 0x0E,
1160      networkId: "xxxxxxx",
1161      range: 0,
1162      authForm: 0
1163    };
1164    dmInstance.unAuthenticateDevice(deviceInfo);
1165  } catch (err) {
1166    let e: BusinessError = err as BusinessError;
1167    console.error("unAuthenticateDevice errCode:" + e.code + ",errMessage:" + e.message);
1168  }
1169  ```
1170
1171### verifyAuthInfo
1172
1173verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback&lt;{deviceId: string, level: number}&gt;): void;
1174
1175验证认证信息。
1176
1177> 从API version 11 开始废弃。无替代接口。
1178
1179**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1180
1181**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1182
1183**参数:**
1184
1185  | 参数名       | 类型                                     | 必填   | 说明      |
1186  | -------- | ---------------------------------------- | ---- | ------- |
1187  | authInfo | [AuthInfo](#authinfo)                    | 是    | 认证信息。   |
1188  | callback | AsyncCallback&lt;{deviceId:&nbsp;string,&nbsp;level:&nbsp;number}&gt; | 是    | 验证结果回调。 |
1189
1190**错误码:**
1191
1192以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1193
1194| 错误码ID | 错误信息                                                        |
1195| -------- | --------------------------------------------------------------- |
1196| 202 | Permission verification failed. A non-system application calls a system API.                              |
1197| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. |
1198
1199**示例:**
1200
1201示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1202  ```ts
1203  import { BusinessError } from '@ohos.base';
1204
1205  interface ExtraInfo {
1206    authType: number;
1207    token: number;
1208  }
1209
1210  interface AuthInfo {
1211    authType: number;
1212    token: number;
1213    extraInfo: ExtraInfo;
1214  }
1215
1216  class Data {
1217    deviceId: string = "";
1218    level: number = 0;
1219  }
1220
1221  let extraInfo: ExtraInfo = {
1222    authType: 0,
1223    token: 0
1224  };
1225
1226  let authInfo: AuthInfo = {
1227    authType: 1,
1228    token: 123456,
1229    extraInfo: extraInfo
1230  };
1231  try {
1232    dmInstance.verifyAuthInfo(authInfo, (err: BusinessError, data: Data) => {
1233      if (err) {
1234        console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
1235        return;
1236      }
1237    console.info("verifyAuthInfo result:" + JSON.stringify(data));
1238    });
1239  } catch (err) {
1240    let e: BusinessError = err as BusinessError;
1241    console.error("verifyAuthInfo errCode:" + e.code + ",errMessage:" + e.message);
1242  }
1243  ```
1244
1245### setUserOperation<sup>9+</sup>
1246
1247setUserOperation(operateAction: number, params: string): void;
1248
1249设置用户ui操作行为。
1250
1251> 从API version 11 开始废弃。建议使用[replyUiAction](js-apis-distributedDeviceManager-sys.md#replyuiaction)替代。
1252
1253**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1254
1255**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1256
1257**参数:**
1258
1259  | 参数名       | 类型            | 必填  | 说明                |
1260  | ------------- | --------------- | ---- | ------------------- |
1261  | operateAction | number          | 是    | 用户操作动作。取值范围为0~5。       |
1262  | params        | string          | 是    | 表示用户的输入参数。长度范围1~255字符。 |
1263
1264**错误码:**
1265
1266以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1267
1268| 错误码ID | 错误信息                                                        |
1269| -------- | --------------------------------------------------------------- |
1270| 201 | Permission verification failed. The application does not have the permission required to call the API.    |
1271| 202 | Permission verification failed. A non-system application calls a system API.                              |
1272| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified params is greater than 255.    |
1273
1274**示例:**
1275
1276示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1277  ```ts
1278  import { BusinessError } from '@ohos.base';
1279
1280 try {
1281    /*
1282      operateAction = 0 - 允许授权
1283      operateAction = 1 - 取消授权
1284      operateAction = 2 - 授权框用户操作超时
1285      operateAction = 3 - 取消pin码框展示
1286      operateAction = 4 - 取消pin码输入框展示
1287      operateAction = 5 - pin码输入框确定操作
1288    */
1289    let operation = 0;
1290    dmInstance.setUserOperation(operation, "extra");
1291  } catch (err) {
1292    let e: BusinessError = err as BusinessError;
1293    console.error("setUserOperation errCode:" + e.code + ",errMessage:" + e.message);
1294  }
1295  ```
1296
1297### requestCredentialRegisterInfo<sup>10+</sup>
1298
1299requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{registerInfo: string}>): void;
1300
1301获取凭据的注册信息。
1302
1303> 从API version 11 开始废弃。无替代接口。
1304
1305**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1306
1307**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1308
1309**参数:**
1310
1311  | 参数名       | 类型            | 必填  | 说明                |
1312  | ------------- | --------------- | ---- | ------------------- |
1313  | requestInfo   | string          | 是    | 请求凭据信息。最大长度255字符。       |
1314  | callback      | AsyncCallback<{registerInfo: string}>         | 是    | 凭据的注册信息回调。 |
1315
1316**错误码:**
1317
1318以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1319
1320| 错误码ID | 错误信息                                                        |
1321| -------- | --------------------------------------------------------------- |
1322| 202 | Permission verification failed. A non-system application calls a system API.                              |
1323| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified params is greater than 255.    |
1324
1325**示例:**
1326
1327示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1328  ```ts
1329  import { BusinessError } from '@ohos.base';
1330
1331  interface CredentialInfo {
1332    version: string;
1333    userId: string;
1334  }
1335
1336  class Data {
1337    registerInfo: string = "";
1338  }
1339
1340  let credentialInfo: CredentialInfo = {
1341    version: "1.2.3",
1342    userId: "123"
1343  };
1344  try {
1345    let jsonCredentialInfo = JSON.stringify(credentialInfo);
1346    dmInstance.requestCredentialRegisterInfo(jsonCredentialInfo, (err: BusinessError, data: Data) => {
1347      if (data) {
1348        console.info("requestCredentialRegisterInfo result:" + JSON.stringify(data));
1349      } else {
1350        console.info("requestCredentialRegisterInfo result: data is null");
1351      }
1352    });
1353  } catch (err) {
1354    let e: BusinessError = err as BusinessError;
1355    console.error("requestCredentialRegisterInfo err:" + e.code + "," + e.message);
1356  }
1357  ```
1358
1359### importCredential<sup>10+</sup>
1360
1361importCredential(credentialInfo: string, callback: AsyncCallback<{resultInfo: string}>): void;
1362
1363导入凭据信息。
1364
1365> 从API version 11 开始废弃。无替代接口。
1366
1367**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1368
1369**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1370
1371**参数:**
1372
1373  | 参数名       | 类型            | 必填  | 说明                |
1374  | ------------- | --------------- | ---- | ------------------- |
1375  | credentialInfo| string          | 是    | 导入凭据信息。长度范围1~64000字符。       |
1376  | callback      | AsyncCallback<{resultInfo: string}>           | 是    | 导入凭据结果回调。 |
1377
1378**错误码:**
1379
1380以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1381
1382| 错误码ID | 错误信息                                                        |
1383| -------- | --------------------------------------------------------------- |
1384| 202 | Permission verification failed. A non-system application calls a system API.                              |
1385| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified credentialInfo is greater than 5999. |
1386
1387**示例:**
1388
1389示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1390<!--code_no_check-->
1391  ```ts
1392  import { BusinessError } from '@ohos.base';
1393
1394  class Data {
1395    resultInfo: string = "";
1396  }
1397
1398  interface CredentialData {
1399    credentialType: number;
1400    credentialId: string;
1401    serverPk: string;
1402    pkInfoSignature : string;
1403    pkInfo: string;
1404    authCode: string;
1405    peerDeviceId: string;
1406  }
1407
1408  interface CredentialInfo {
1409    processType: number;
1410    authType: number;
1411    userId: string;
1412    deviceId: string;
1413    version: string;
1414    devicePk : string;
1415    credentialData : CredentialData;
1416  }
1417
1418  let credentialData: CredentialData = {
1419    credentialType: 2,
1420    credentialId: "102",
1421    serverPk: "3059301306072A8648CE3D020106082A8648CE3D03",
1422    pkInfoSignature : "30440220490BCB4F822004C9A76AB8D97F80041FC0E",
1423    pkInfo: "",
1424    authCode: "",
1425    peerDeviceId: ""
1426  };
1427
1428
1429  let credentialInfo: CredentialInfo = {
1430    processType: 1,
1431    authType: 1,
1432    userId: "123",
1433    deviceId: "aaa",
1434    version: "1.2.3",
1435    devicePk : "0000",
1436    credentialData : credentialData
1437  };
1438
1439  try {
1440    let jsonCredentialInfo = JSON.stringify(credentialInfo);
1441    dmInstance.importCredential(jsonCredentialInfo, (err: BusinessError, data: Data) => {
1442      if (data) {
1443        console.info("importCredential result:" + JSON.stringify(data));
1444      } else {
1445        console.info("importCredential result: data is null");
1446      }
1447    });
1448  } catch (err) {
1449    let e: BusinessError = err as BusinessError;
1450    console.error("importCredential err:" + e.code + "," + e.message);
1451  }
1452  ```
1453
1454### deleteCredential<sup>10+</sup>
1455
1456deleteCredential(queryInfo: string, callback: AsyncCallback<{resultInfo: string}>): void;
1457
1458删除凭据信息。
1459
1460> 从API version 11 开始废弃。无替代接口。
1461
1462**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1463
1464**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1465
1466**参数:**
1467
1468  | 参数名       | 类型            | 必填  | 说明                |
1469  | ------------- | --------------- | ---- | ------------------- |
1470  | queryInfo     | string          | 是    | 删除凭据信息。长度范围1~64000字符。       |
1471  | callback      | AsyncCallback<{resultInfo: string}>           | 是    | 删除凭据结果回调。 |
1472
1473**错误码:**
1474
1475以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1476
1477| 错误码ID | 错误信息                                                        |
1478| -------- | --------------------------------------------------------------- |
1479| 202 | Permission verification failed. A non-system application calls a system API.                              |
1480| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified credentialInfo is greater than 5999. |
1481
1482**示例:**
1483
1484示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1485  ```ts
1486  import { BusinessError } from '@ohos.base';
1487
1488  class Data {
1489    resultInfo: string = "";
1490  }
1491
1492  interface QueryInfo {
1493    processType: number;
1494    authType: number;
1495    userId: string;
1496  }
1497
1498  let queryInfo: QueryInfo = {
1499    processType: 1,
1500    authType: 1,
1501    userId: "123"
1502  };
1503
1504  try {
1505    let jsonQueryInfo = JSON.stringify(queryInfo);
1506    dmInstance.deleteCredential(jsonQueryInfo, (err: BusinessError, data: Data) => {
1507      if (data) {
1508        console.info("deleteCredential result:" + JSON.stringify(data));
1509      } else {
1510        console.info("deleteCredential result: data is null");
1511      }
1512    });
1513  } catch (err) {
1514    let e: BusinessError = err as BusinessError;
1515    console.error("deleteCredential err:" + e.code + "," + e.message);
1516  }
1517  ```
1518
1519### on('uiStateChange')<sup>9+</sup>
1520
1521on(type: 'uiStateChange', callback: Callback&lt;{ param: string}&gt;): void;
1522
1523ui状态变更回调。
1524
1525> 从API version 11 开始废弃。建议使用[on('replyResult')](js-apis-distributedDeviceManager-sys.md#onreplyresult)替代。
1526
1527**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1528
1529**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1530
1531**参数:**
1532
1533  | 参数名      | 类型                             | 必填 | 说明                            |
1534  | -------- | ------------------------------------ | ---- | ------------------------------ |
1535  | type     | string                                | 是  | 注册的设备管理器 ui 状态回调,以便在状态改变时通知应用,固定为uiStateChange。 |
1536  | callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | 是  | 指示要注册的设备管理器 ui 状态回调,返回ui状态。        |
1537
1538**错误码:**
1539
1540以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1541
1542| 错误码ID | 错误信息                                                        |
1543| -------- | --------------------------------------------------------------- |
1544| 202 | Permission verification failed. A non-system application calls a system API.                              |
1545| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
1546
1547**示例:**
1548
1549示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1550  ```ts
1551  import { BusinessError } from '@ohos.base';
1552
1553  class Data {
1554    param: string = "";
1555  }
1556
1557  interface TmpStr {
1558    verifyFailed: boolean;
1559  }
1560
1561  try {
1562    dmInstance.on('uiStateChange', (data: Data) => {
1563      console.log("uiStateChange executed, dialog closed" + JSON.stringify(data));
1564      let tmpStr: TmpStr = JSON.parse(data.param);
1565      let isShow = tmpStr.verifyFailed;
1566      console.log("uiStateChange executed, dialog closed" + isShow);
1567    });
1568  } catch (err) {
1569    let e: BusinessError = err as BusinessError;
1570    console.error("uiStateChange errCode:" + e.code + ",errMessage:" + e.message);
1571  }
1572  ```
1573
1574### off('uiStateChange')<sup>9+</sup>
1575
1576off(type: 'uiStateChange', callback?: Callback&lt;{ param: string}&gt;): void;
1577
1578取消ui状态变更回调。
1579
1580> 从API version 11 开始废弃。建议使用[off('replyResult')](js-apis-distributedDeviceManager-sys.md#offreplyresult)替代。
1581
1582**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1583
1584**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1585
1586**参数:**
1587
1588  | 参数名      | 类型                              | 必填 | 说明                            |
1589  | -------- | ------------------------------------- | ---- | ------------------------------ |
1590  | type     | string                                | 是   | 取消注册的设备管理器 ui 状态回调,固定为uiStateChange。 |
1591  | callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | 否   | 指示要取消注册的设备管理器 ui 状态,返回UI状态。 |
1592
1593**错误码:**
1594
1595以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1596
1597| 错误码ID | 错误信息                                                        |
1598| -------- | --------------------------------------------------------------- |
1599| 202 | Permission verification failed. A non-system application calls a system API.                              |
1600| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
1601
1602**示例:**
1603
1604示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1605  ```ts
1606  import { BusinessError } from '@ohos.base';
1607
1608  try {
1609    dmInstance.off('uiStateChange');
1610  } catch (err) {
1611    let e: BusinessError = err as BusinessError;
1612    console.error("uiStateChange errCode:" + e.code + ",errMessage:" + e.message);
1613  }
1614  ```
1615
1616### on('deviceStateChange')
1617
1618on(type: 'deviceStateChange',  callback: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void;
1619
1620注册设备状态回调。
1621
1622> 从API version 11 开始废弃。建议使用[on('deviceStateChange')](js-apis-distributedDeviceManager.md#ondevicestatechange)替代。
1623
1624**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1625
1626**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1627
1628**参数:**
1629
1630  | 参数名       | 类型                                     | 必填   | 说明                             |
1631  | -------- | ---------------------------------------- | ---- | ------------------------------ |
1632  | type     | string                                   | 是    | 注册设备状态回调,固定为deviceStateChange。 |
1633  | callback | Callback&lt;{&nbsp;action:&nbsp;[DeviceStateChangeAction](#devicestatechangeaction),&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | 是    | 指示要注册的设备状态回调,返回设备状态和设备信息。      |
1634
1635**错误码:**
1636
1637以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1638
1639| 错误码ID | 错误信息                                                        |
1640| -------- | --------------------------------------------------------------- |
1641| 202 | Permission verification failed. A non-system application calls a system API.                              |
1642| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
1643
1644**示例:**
1645
1646示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1647  ```ts
1648  import deviceManager from '@ohos.distributedHardware.deviceManager';
1649  import { BusinessError } from '@ohos.base';
1650
1651  class Data {
1652    action: deviceManager.DeviceStateChangeAction = 0;
1653    device: deviceManager.DeviceInfo = {
1654      deviceId: "",
1655      deviceName: "",
1656      deviceType: 0,
1657      networkId: "",
1658      range: 0,
1659      authForm:0
1660    };
1661  }
1662
1663  try {
1664    dmInstance.on('deviceStateChange', (data: Data) => {
1665      console.info("deviceStateChange on:" + JSON.stringify(data));
1666    });
1667  } catch (err) {
1668    let e: BusinessError = err as BusinessError;
1669    console.error("deviceStateChange errCode:" + e.code + ",errMessage:" + e.message);
1670  }
1671  ```
1672
1673### off('deviceStateChange')
1674
1675off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void;
1676
1677取消注册设备状态回调。
1678
1679> 从API version 11 开始废弃。建议使用[off('deviceStateChange')](js-apis-distributedDeviceManager.md#offdevicestatechange)替代。
1680
1681**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1682
1683**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1684
1685**参数:**
1686
1687  | 参数名       | 类型                                     | 必填   | 说明                          |
1688  | -------- | ---------------------------------------- | ---- | --------------------------- |
1689  | type     | string                                   | 是    | 根据应用程序的包名取消注册设备状态回调,固定为deviceStateChange。        |
1690  | callback | Callback&lt;{&nbsp;action:&nbsp;[DeviceStateChangeAction](#devicestatechangeaction),&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | 否    | 指示要取消注册的设备状态回调,返回设备状态和设备信息。 |
1691
1692**错误码:**
1693
1694以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1695
1696| 错误码ID | 错误信息                                                        |
1697| -------- | --------------------------------------------------------------- |
1698| 202 | Permission verification failed. A non-system application calls a system API.                              |
1699| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
1700
1701**示例:**
1702
1703示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1704  ```ts
1705  import deviceManager from '@ohos.distributedHardware.deviceManager';
1706  import { BusinessError } from '@ohos.base';
1707
1708  class Data {
1709    action: deviceManager.DeviceStateChangeAction = 0;
1710    device: deviceManager.DeviceInfo = {
1711      deviceId: "",
1712      deviceName: "",
1713      deviceType: 0,
1714      networkId: "",
1715      range: 0,
1716      authForm:0
1717    };
1718  }
1719
1720  try {
1721    dmInstance.off('deviceStateChange', (data: Data) => {
1722      console.info('deviceStateChange' + JSON.stringify(data));
1723    });
1724  } catch (err) {
1725    let e: BusinessError = err as BusinessError;
1726    console.error("deviceStateChange errCode:" + e.code + ",errMessage:" + e.message);
1727  }
1728  ```
1729
1730### on('deviceFound')
1731
1732on(type: 'deviceFound', callback: Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt;): void;
1733
1734注册发现设备回调监听。
1735
1736> 从API version 11 开始废弃。建议使用[on('discoverSuccess')](js-apis-distributedDeviceManager.md#ondiscoversuccess)替代。
1737
1738**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1739
1740**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1741
1742**参数:**
1743
1744  | 参数名       | 类型                                     | 必填   | 说明                         |
1745  | -------- | ---------------------------------------- | ---- | -------------------------- |
1746  | type     | string                                   | 是    | 注册设备发现回调,以便在发现周边设备时通知应用程序,固定为deviceFound。 |
1747  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | 是    | 注册设备发现的回调方法。               |
1748
1749**错误码:**
1750
1751以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1752
1753| 错误码ID | 错误信息                                                        |
1754| -------- | --------------------------------------------------------------- |
1755| 202 | Permission verification failed. A non-system application calls a system API.                              |
1756| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
1757
1758**示例:**
1759
1760示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1761  ```ts
1762  import deviceManager from '@ohos.distributedHardware.deviceManager';
1763  import { BusinessError } from '@ohos.base';
1764
1765  class Data {
1766    subscribeId: number = 0;
1767    device: deviceManager.DeviceInfo = {
1768      deviceId: "",
1769      deviceName: "",
1770      deviceType: 0,
1771      networkId: "",
1772      range: 0,
1773      authForm:0
1774    };
1775  }
1776
1777  try {
1778    dmInstance.on('deviceFound', (data: Data) => {
1779      console.info("deviceFound:" + JSON.stringify(data));
1780    });
1781  } catch (err) {
1782    let e: BusinessError = err as BusinessError;
1783    console.error("deviceFound errCode:" + e.code + ",errMessage:" + e.message);
1784  }
1785  ```
1786
1787### off('deviceFound')
1788
1789off(type: 'deviceFound', callback?: Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt;): void;
1790
1791取消注册设备发现回调。
1792
1793> 从API version 11 开始废弃。建议使用[off('discoverSuccess')](js-apis-distributedDeviceManager.md#offdiscoversuccess)替代。
1794
1795**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1796
1797**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1798
1799**参数:**
1800
1801  | 参数名       | 类型                                     | 必填   | 说明                          |
1802  | -------- | ---------------------------------------- | ---- | --------------------------- |
1803  | type     | string                                   | 是    | 取消注册设备发现回调,固定为deviceFound。                |
1804  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | 否    | 指示要取消注册的设备发现回调,返回设备状态和设备信息。 |
1805
1806**错误码:**
1807
1808以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1809
1810| 错误码ID | 错误信息                                                        |
1811| -------- | --------------------------------------------------------------- |
1812| 202 | Permission verification failed. A non-system application calls a system API.                              |
1813| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
1814
1815**示例:**
1816
1817示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1818  ```ts
1819  import deviceManager from '@ohos.distributedHardware.deviceManager';
1820  import { BusinessError } from '@ohos.base';
1821
1822  class Data {
1823    subscribeId: number = 0;
1824    device: deviceManager.DeviceInfo = {
1825      deviceId: "",
1826      deviceName: "",
1827      deviceType: 0,
1828      networkId: "",
1829      range: 0,
1830      authForm:0
1831    };
1832  }
1833
1834  try {
1835    dmInstance.off('deviceFound', (data: Data) => {
1836      console.info('deviceFound' + JSON.stringify(data));
1837    });
1838  } catch (err) {
1839    let e: BusinessError = err as BusinessError;
1840    console.error("deviceFound errCode:" + e.code + ",errMessage:" + e.message);
1841  }
1842  ```
1843
1844### on('discoverFail')
1845
1846on(type: 'discoverFail', callback: Callback&lt;{ subscribeId: number, reason: number }&gt;): void;
1847
1848注册设备发现失败回调监听。
1849
1850> 从API version 11 开始废弃。建议使用[on('discoverFailure')](js-apis-distributedDeviceManager.md#ondiscoverfailure)替代。
1851
1852**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1853
1854**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1855
1856**参数:**
1857
1858  | 参数名       | 类型                                     | 必填   | 说明                             |
1859  | -------- | ---------------------------------------- | ---- | ------------------------------ |
1860  | type     | string                                   | 是    | 注册设备发现失败回调,以便在发现周边设备失败时通知应用程序,固定为discoverFail。 |
1861  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | 是    | 注册设备发现失败的回调方法。                 |
1862
1863**错误码:**
1864
1865以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1866
1867| 错误码ID | 错误信息                                                        |
1868| -------- | --------------------------------------------------------------- |
1869| 202 | Permission verification failed. A non-system application calls a system API.                              |
1870| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
1871
1872**示例:**
1873
1874示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1875  ```ts
1876  import { BusinessError } from '@ohos.base';
1877
1878  class Data {
1879    subscribeId: number = 0;
1880    reason: number = 0;
1881  }
1882
1883  try {
1884    dmInstance.on('discoverFail', (data: Data) => {
1885      console.info("discoverFail on:" + JSON.stringify(data));
1886    });
1887  } catch (err) {
1888    let e: BusinessError = err as BusinessError;
1889    console.error("discoverFail errCode:" + e.code + ",errMessage:" + e.message);
1890  }
1891  ```
1892
1893### off('discoverFail')
1894
1895off(type: 'discoverFail', callback?: Callback&lt;{ subscribeId: number, reason: number }&gt;): void;
1896
1897取消注册设备发现失败回调。
1898
1899> 从API version 11 开始废弃。建议使用[off('discoverFailure')](js-apis-distributedDeviceManager.md#offdiscoverfailure)替代。
1900
1901**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1902
1903**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1904
1905**参数:**
1906
1907  | 参数名       | 类型                                     | 必填   | 说明                |
1908  | -------- | ---------------------------------------- | ---- | ----------------- |
1909  | type     | string                                   | 是    | 取消注册设备发现失败回调,固定为discoverFail。     |
1910  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | 否    | 指示要取消注册的设备发现失败回调。 |
1911
1912**错误码:**
1913
1914以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1915
1916| 错误码ID | 错误信息                                                        |
1917| -------- | --------------------------------------------------------------- |
1918| 202 | Permission verification failed. A non-system application calls a system API.                              |
1919| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
1920
1921**示例:**
1922
1923示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1924  ```ts
1925  import { BusinessError } from '@ohos.base';
1926
1927  class Data {
1928    subscribeId: number = 0;
1929    reason: number = 0;
1930  }
1931
1932  try {
1933    dmInstance.off('discoverFail', (data: Data) => {
1934      console.info('discoverFail' + JSON.stringify(data));
1935    });
1936  } catch (err) {
1937    let e: BusinessError = err as BusinessError;
1938    console.error("discoverFail errCode:" + e.code + ",errMessage:" + e.message);
1939  }
1940  ```
1941
1942### on('publishSuccess')<sup>9+</sup>
1943
1944on(type: 'publishSuccess', callback: Callback&lt;{ publishId: number }&gt;): void;
1945
1946注册发布设备发现回调监听。
1947
1948> 从API version 11 开始废弃。无替代接口。
1949
1950**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1951
1952**系统能力**:SystemCapability.DistributedHardware.DeviceManager
1953
1954**参数:**
1955
1956  | 参数名     | 类型                                 | 必填 | 说明                       |
1957  | -------- | ---------------------------------------- | ---- | -------------------------- |
1958  | type     | string                                   | 是   | 注册发布设备成功回调,以便将发布成功时通知应用程序,固定为publishSuccess。 |
1959  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number&nbsp;}&gt;    | 是   | 注册设备发布成功的回调方法。               |
1960
1961**错误码:**
1962
1963以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1964
1965| 错误码ID | 错误信息                                                        |
1966| -------- | --------------------------------------------------------------- |
1967| 202 | Permission verification failed. A non-system application calls a system API.                              |
1968| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
1969
1970**示例:**
1971
1972示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
1973  ```ts
1974  import { BusinessError } from '@ohos.base';
1975
1976  class Data {
1977    publishId: number = 0;
1978  }
1979
1980  try {
1981    dmInstance.on('publishSuccess', (data: Data) => {
1982      console.info("publishSuccess:" + JSON.stringify(data));
1983    });
1984  } catch (err) {
1985    let e: BusinessError = err as BusinessError;
1986    console.error("publishSuccess errCode:" + e.code + ",errMessage:" + e.message);
1987  }
1988  ```
1989
1990### off('publishSuccess')<sup>9+</sup>
1991
1992off(type: 'publishSuccess', callback?: Callback&lt;{ publishId: number }&gt;): void;
1993
1994取消注册设备发布成功回调。
1995
1996> 从API version 11 开始废弃。无替代接口。
1997
1998**需要权限**:ohos.permission.ACCESS_SERVICE_DM
1999
2000**系统能力**:SystemCapability.DistributedHardware.DeviceManager
2001
2002**参数:**
2003
2004  | 参数名     | 类型                                 | 必填 | 说明                          |
2005  | -------- | ---------------------------------------- | ---- | --------------------------- |
2006  | type     | string                                   | 是   | 取消注册设备发布成功回调,固定为publishSuccess。                 |
2007  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number&nbsp;}&gt;    | 否   | 指示要取消注册的设备发布成功回调。 |
2008
2009**错误码:**
2010
2011以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2012
2013| 错误码ID | 错误信息                                                        |
2014| -------- | --------------------------------------------------------------- |
2015| 202 | Permission verification failed. A non-system application calls a system API.                              |
2016| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
2017
2018**示例:**
2019
2020示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
2021  ```ts
2022  import { BusinessError } from '@ohos.base';
2023
2024  class Data {
2025    publishId: number = 0;
2026  }
2027
2028  try {
2029    dmInstance.off('publishSuccess', (data: Data) => {
2030      console.info('publishSuccess' + JSON.stringify(data));
2031    });
2032  } catch (err) {
2033    let e: BusinessError = err as BusinessError;
2034    console.error("publishSuccess errCode:" + e.code + ",errMessage:" + e.message);
2035  }
2036  ```
2037
2038### on('publishFail')<sup>9+</sup>
2039
2040on(type: 'publishFail', callback: Callback&lt;{ publishId: number, reason: number }&gt;): void;
2041
2042注册设备发布失败回调监听。
2043
2044> 从API version 11 开始废弃。无替代接口。
2045
2046**需要权限**:ohos.permission.ACCESS_SERVICE_DM
2047
2048**系统能力**:SystemCapability.DistributedHardware.DeviceManager
2049
2050**参数:**
2051
2052  | 参数名     | 类型                                              | 必填 | 说明                             |
2053  | -------- | ----------------------------------------------------- | ---- | ------------------------------ |
2054  | type     | string                                                | 是   | 注册设备发布失败回调,以便在发布设备失败时通知应用程序,固定为publishFail。 |
2055  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | 是   | 注册设备发布失败的回调方法。                 |
2056
2057**错误码:**
2058
2059以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2060
2061| 错误码ID | 错误信息                                                        |
2062| -------- | --------------------------------------------------------------- |
2063| 202 | Permission verification failed. A non-system application calls a system API.                              |
2064| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
2065
2066**示例:**
2067
2068示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
2069  ```ts
2070  import { BusinessError } from '@ohos.base';
2071
2072  class Data {
2073    publishId: number = 0;
2074    reason: number = 0;
2075  }
2076
2077  try {
2078    dmInstance.on('publishFail', (data: Data) => {
2079      console.info("publishFail on:" + JSON.stringify(data));
2080    });
2081  } catch (err) {
2082    let e: BusinessError = err as BusinessError;
2083    console.error("publishFail errCode:" + e.code + ",errMessage:" + e.message);
2084  }
2085  ```
2086
2087### off('publishFail')<sup>9+</sup>
2088
2089off(type: 'publishFail', callback?: Callback&lt;{ publishId: number, reason: number }&gt;): void;
2090
2091取消注册设备发布失败回调。
2092
2093> 从API version 11 开始废弃。无替代接口。
2094
2095**需要权限**:ohos.permission.ACCESS_SERVICE_DM
2096
2097**系统能力**:SystemCapability.DistributedHardware.DeviceManager
2098
2099**参数:**
2100
2101  | 参数名     | 类型                                              | 必填 | 说明                |
2102  | -------- | ----------------------------------------------------- | ---- | ----------------- |
2103  | type     | string                                                | 是   | 取消注册设备发布失败回调,固定为publishFail。     |
2104  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | 否   | 指示要取消注册设备发布失败回调。 |
2105
2106**错误码:**
2107
2108以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2109
2110| 错误码ID | 错误信息                                                        |
2111| -------- | --------------------------------------------------------------- |
2112| 202 | Permission verification failed. A non-system application calls a system API.                              |
2113| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
2114
2115**示例:**
2116
2117示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
2118  ```ts
2119  import { BusinessError } from '@ohos.base';
2120
2121  class Data {
2122    publishId: number = 0;
2123    reason: number = 0;
2124  }
2125
2126  try {
2127    dmInstance.off('publishFail', (data: Data) => {
2128      console.info('publishFail' + JSON.stringify(data));
2129    });
2130  } catch (err) {
2131    let e: BusinessError = err as BusinessError;
2132    console.error("publishFail errCode:" + e.code + ",errMessage:" + e.message);
2133  }
2134  ```
2135
2136### on('serviceDie')
2137
2138on(type: 'serviceDie', callback: () =&gt; void): void;
2139
2140注册设备管理服务死亡监听。
2141
2142> 从API version 11 开始废弃。建议使用[on('serviceDie')](js-apis-distributedDeviceManager.md#onservicedie)替代。
2143
2144**需要权限**:ohos.permission.ACCESS_SERVICE_DM
2145
2146**系统能力**:SystemCapability.DistributedHardware.DeviceManager
2147
2148**参数:**
2149
2150  | 参数名       | 类型                    | 必填   | 说明                                       |
2151  | -------- | ----------------------- | ---- | ---------------------------------------- |
2152  | type     | string                  | 是    | 注册serviceDie回调,以便在devicemanager服务异常终止时通知应用程序,固定为serviceDie。 |
2153  | callback | ()&nbsp;=&gt;&nbsp;void | 是    | 注册serviceDie的回调方法。                       |
2154
2155**错误码:**
2156
2157以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2158
2159| 错误码ID | 错误信息                                                        |
2160| -------- | --------------------------------------------------------------- |
2161| 202 | Permission verification failed. A non-system application calls a system API.                              |
2162| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
2163
2164**示例:**
2165
2166示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
2167  ```ts
2168  import { BusinessError } from '@ohos.base';
2169
2170  try {
2171    dmInstance.on("serviceDie", () => {
2172      console.info("serviceDie on");
2173    });
2174  } catch (err) {
2175    let e: BusinessError = err as BusinessError;
2176    console.error("serviceDie errCode:" + e.code + ",errMessage:" + e.message);
2177  }
2178  ```
2179
2180### off('serviceDie')
2181
2182off(type: 'serviceDie', callback?: () =&gt; void): void;
2183
2184取消注册设备管理服务死亡监听。
2185
2186> 从API version 11 开始废弃。建议使用[off('serviceDie')](js-apis-distributedDeviceManager.md#offservicedie)替代。
2187
2188**需要权限**:ohos.permission.ACCESS_SERVICE_DM
2189
2190**系统能力**:SystemCapability.DistributedHardware.DeviceManager
2191
2192**参数:**
2193
2194  | 参数名       | 类型                    | 必填   | 说明                                       |
2195  | -------- | ----------------------- | ---- | ---------------------------------------- |
2196  | type     | string                  | 是    | 取消注册serviceDie回调,以便在devicemanager服务异常终止时通知应用程序,固定为serviceDie。 |
2197  | callback | ()&nbsp;=&gt;&nbsp;void | 否    | 取消注册serviceDie的回调方法。                     |
2198
2199**错误码:**
2200
2201以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2202
2203| 错误码ID | 错误信息                                                        |
2204| -------- | --------------------------------------------------------------- |
2205| 202 | Permission verification failed. A non-system application calls a system API.                              |
2206| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. 4. The size of specified eventType is greater than 255. |
2207
2208**示例:**
2209
2210示例中`dmInstance`的初始化请参见[DM初始化](#devicemanagercreatedevicemanager)。
2211  ```ts
2212  import { BusinessError } from '@ohos.base';
2213
2214  try {
2215    dmInstance.off("serviceDie", () => {
2216      console.info("serviceDie off");
2217    });
2218  } catch (err) {
2219    let e: BusinessError = err as BusinessError;
2220    console.error("serviceDie errCode:" + e.code + ",errMessage:" + e.message);
2221  }
2222  ```