• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.distributedHardware.deviceManager (Device Management)
2
3The APIs of this module are deprecated. You are advised to use [@ohos.distributedDeviceManager](js-apis-distributedDeviceManager.md).
4
5The **distributedHardware.deviceManager** module provides APIs for distributed device management.
6
7System applications can call the APIs to do the following:
8
9- Subscribe to or unsubscribe from device state changes.
10- Discover peripheral untrusted devices.
11- Authenticate or deauthenticate a device.
12- Query the trusted device list.
13- Query local device information, including the device name, type, and ID.
14- Publish device information for discovery purposes.
15
16> **NOTE**
17>
18> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
19> - The APIs of this module are system APIs and cannot be called by third-party applications.
20
21
22## Modules to Import
23
24```ts
25import deviceManager from '@ohos.distributedHardware.deviceManager';
26```
27
28
29## deviceManager.createDeviceManager
30
31createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void
32
33Creates a **DeviceManager** instance.
34
35> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [deviceManager.createDeviceManager](js-apis-distributedDeviceManager.md#devicemanagercreatedevicemanager).
36
37**System capability**: SystemCapability.DistributedHardware.DeviceManager
38
39**Parameters**
40
41| Name    | Type                                                | Mandatory| Description                                                       |
42| ---------- | ---------------------------------------------------- | ---- | ----------------------------------------------------------- |
43| bundleName | string                                               | Yes  | Bundle name of the application.                                 |
44| callback   | AsyncCallback&lt;[DeviceManager](#devicemanager)&gt; | Yes  | Callback invoked to return the **DeviceManager** instance created.|
45
46**Example**
47
48  ```ts
49  import deviceManager from '@ohos.distributedHardware.deviceManager';
50  import { BusinessError } from '@ohos.base';
51
52  let dmInstance: deviceManager.DeviceManager | null = null;
53  try {
54    deviceManager.createDeviceManager("ohos.samples.jshelloworld", (err: BusinessError, data: deviceManager.DeviceManager) => {
55      if (err) {
56        console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
57        return;
58      }
59      console.info("createDeviceManager success");
60      dmInstance = data;
61    });
62  } catch(err) {
63    let e: BusinessError = err as BusinessError;
64    console.error("createDeviceManager errCode:" + e.code + ",errMessage:" + e.message);
65  }
66  ```
67
68## DeviceInfo
69
70Defines device information.
71
72> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [DeviceBasicInfo](js-apis-distributedDeviceManager.md#devicebasicinfo).
73
74**System capability**: SystemCapability.DistributedHardware.DeviceManager
75
76| Name                    | Type                       | Mandatory  | Description      |
77| ---------------------- | ------------------------- | ---- | -------- |
78| deviceId               | string                    | Yes   | Unique identifier of the device.|
79| deviceName             | string                    | Yes   | Device name.   |
80| deviceType             | [DeviceType](#devicetype) | Yes   | Device type.   |
81| networkId<sup>8+</sup> | string                    | Yes   | Network ID of the device. |
82| range<sup>9+</sup>     | number                    | Yes   | Distance between the discovered device and the device that initiates device discovery. |
83| authForm<sup>10+</sup> | [AuthForm](#authform)     | Yes   | Authentication type of the device. |
84
85## DeviceType
86
87Enumerates the device types.
88
89> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
90
91**System capability**: SystemCapability.DistributedHardware.DeviceManager
92
93| Name          | Value | Description  |
94| ------------ | ---- | ---- |
95| SPEAKER      | 0x0A | Smart speaker.|
96| PHONE        | 0x0E | Phone.  |
97| TABLET       | 0x11 | Tablet.  |
98| WEARABLE     | 0x6D | Wearable.|
99| TV           | 0x9C | Smart TV. |
100| CAR          | 0x83 | Car.   |
101| UNKNOWN_TYPE | 0    | Unknown device type.|
102
103## AuthForm<sup>10+</sup>
104
105Enumerates the device authentication types.
106
107> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
108
109**System capability**: SystemCapability.DistributedHardware.DeviceManager
110
111| Name                | Value | Description            |
112| ------------------- | ---- | --------------- |
113| INVALID_TYPE        | -1   | No authentication.|
114| PEER_TO_PEER        | 0    | Point-to-point authentication for devices without accounts.  |
115| IDENTICAL_ACCOUNT   | 1    | Authentication for devices using the same account.  |
116| ACROSS_ACCOUNT      | 2    | Authentication for devices using different accounts.|
117
118## DeviceStateChangeAction
119
120Enumerates the device states.
121
122> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [DeviceStateChange](js-apis-distributedDeviceManager.md#devicestatechange).
123
124**System capability**: SystemCapability.DistributedHardware.DeviceManager
125
126| Name     | Value | Description             |
127| ------- | ---- | --------------- |
128| ONLINE  | 0    | The device is physically online.          |
129| READY   | 1    | The information between devices has been synchronized in the Distributed Data Service (DDS) module, and the device is ready for running distributed services.|
130| OFFLINE | 2    | The device is physically offline.          |
131| CHANGE  | 3    | The device information is changed.        |
132
133## SubscribeInfo
134
135Defines subscription information.
136
137> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
138
139**System capability**: SystemCapability.DistributedHardware.DeviceManager
140
141| Name           | Type                               | Mandatory  | Description               |
142| ------------- | --------------------------------- | ---- | ----------------- |
143| subscribeId   | number                            | Yes   | Subscription ID, used to identify a device discovery period.|
144| mode          | [DiscoverMode ](#discovermode)    | Yes   | Device discovery mode.            |
145| medium        | [ExchangeMedium](#exchangemedium) | Yes   | Medium used for device discovery.            |
146| freq          | [ExchangeFreq](#exchangefreq)     | Yes   | Frequency of device discovery.            |
147| isSameAccount | boolean                           | No   | Whether the same account is used on the discovered device.           |
148| isWakeRemote  | boolean                           | No   | Whether to wake up the discovered device.          |
149| capability    | [SubscribeCap](#subscribecap)     | Yes   | Discovery capability.            |
150
151
152## DiscoverMode
153
154Enumerates the device discovery modes.
155
156> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
157
158**System capability**: SystemCapability.DistributedHardware.DeviceManager
159
160| Name                   | Value | Description   |
161| --------------------- | ---- | ----- |
162| DISCOVER_MODE_PASSIVE | 0x55 | Passive discovery.|
163| DISCOVER_MODE_ACTIVE  | 0xAA | Active discovery.|
164
165
166## ExchangeMedium
167
168Enumerates the media used for device discovery.
169
170> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
171
172**System capability**: SystemCapability.DistributedHardware.DeviceManager
173
174| Name  | Value | Description       |
175| ---- | ---- | --------- |
176| AUTO | 0    | Automatic.  |
177| BLE  | 1    | Bluetooth.  |
178| COAP | 2    | Wi-Fi.|
179| USB  | 3    | USB. |
180
181## ExchangeFreq
182
183Enumerates the device discovery frequencies.
184
185> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
186
187**System capability**: SystemCapability.DistributedHardware.DeviceManager
188
189| Name        | Value | Description   |
190| ---------- | ---- | ----- |
191| LOW        | 0    | Low frequency. |
192| MID        | 1    | Medium frequency. |
193| HIGH       | 2    | High frequency. |
194| SUPER_HIGH | 3    | Ultra-high frequency.|
195
196
197## SubscribeCap
198
199Enumerates the discovery capabilities.
200
201> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
202
203**System capability**: SystemCapability.DistributedHardware.DeviceManager
204
205| Name                       | Value | Description            |
206| ------------------------- | ---- | -------------- |
207| SUBSCRIBE_CAPABILITY_DDMP | 0    | DDMP capability. This will be deprecated later.|
208| SUBSCRIBE_CAPABILITY_OSD  | 1    | OSD capability.        |
209
210
211## AuthParam
212
213Defines the authentication parameters.
214
215> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
216
217**System capability**: SystemCapability.DistributedHardware.DeviceManager
218
219| Name       | Type                  | Mandatory  | Description        |
220| --------- | -------------------- | ---- | ---------- |
221| authType  | number               | Yes   | Authentication type.     |
222| extraInfo | {[key:string]&nbsp;:&nbsp;any} | No   | Extended field. Optional. The default value is **undefined**.|
223
224## AuthInfo
225
226Defines authentication information.
227
228> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
229
230**System capability**: SystemCapability.DistributedHardware.DeviceManager
231
232| Name       | Type                  | Mandatory  | Description        |
233| --------- | -------------------- | ---- | ---------- |
234| authType  | number               | Yes   | Authentication type.     |
235| token     | number               | Yes   | Authentication token.  |
236| extraInfo | {[key:string]&nbsp;:&nbsp;any} | No   | Extended field. Optional. The default value is **undefined**.|
237
238## PublishInfo<sup>9+</sup>
239
240Defines published device information.
241
242> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
243
244**System capability**: SystemCapability.DistributedHardware.DeviceManager
245
246| Name         | Type                             | Mandatory  | Description               |
247| ------------- | --------------------------------- | ---- | ----------------- |
248| publishId     | number                            | Yes   | ID used to identify a publication period.|
249| mode          | [DiscoverMode ](#discovermode)    | Yes   | Device discovery mode.            |
250| freq          | [ExchangeFreq](#exchangefreq)     | Yes   | Frequency of device discovery.            |
251| ranging       | boolean                           | Yes   | Whether the device supports distance reporting.            |
252
253## DeviceManager
254
255Provides APIs to obtain information about trusted devices and local devices. Before calling any API in **DeviceManager**, you must use **createDeviceManager** to create a **DeviceManager** instance, for example, **dmInstance**.
256
257### release
258
259release(): void
260
261Releases this **DeviceManager** instance when it is no longer used.
262
263> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [deviceManager.releaseDeviceManager](js-apis-distributedDeviceManager.md#devicemanagerreleasedevicemanager).
264
265**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
266
267**System capability**: SystemCapability.DistributedHardware.DeviceManager
268
269**Error codes**
270
271For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
272
273| ID| Error Message                                                       |
274| -------- | --------------------------------------------------------------- |
275| 11600101 | Failed to execute the function.                                 |
276
277**Example**
278
279For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
280  ```ts
281  import { BusinessError } from '@ohos.base';
282
283  try {
284    dmInstance.release();
285  } catch (err) {
286    let e: BusinessError = err as BusinessError;
287    console.error("release errCode:" + e.code + ",errMessage:" + e.message);
288  }
289  ```
290
291### getTrustedDeviceListSync
292
293getTrustedDeviceListSync(): Array&lt;DeviceInfo&gt;
294
295Obtains all trusted devices synchronously.
296
297> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync).
298
299**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
300
301**System capability**: SystemCapability.DistributedHardware.DeviceManager
302
303**Return value**
304
305| Name                                    | Description       |
306| -------------------------------------- | --------- |
307| Array&lt;[DeviceInfo](#deviceinfo)&gt; | List of trusted devices obtained.|
308
309**Error codes**
310
311For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
312
313| ID| Error Message                                                       |
314| -------- | --------------------------------------------------------------- |
315| 11600101 | Failed to execute the function.                                 |
316
317**Example**
318
319For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
320  ```ts
321  import deviceManager from '@ohos.distributedHardware.deviceManager';
322  import { BusinessError } from '@ohos.base';
323
324  try {
325    let deviceInfoList: Array<deviceManager.DeviceInfo> = dmInstance.getTrustedDeviceListSync();
326  } catch (err) {
327    let e: BusinessError = err as BusinessError;
328    console.error("getTrustedDeviceListSync errCode:" + e.code + ",errMessage:" + e.message);
329  }
330  ```
331
332### getTrustedDeviceListSync<sup>10+</sup>
333
334getTrustedDeviceListSync(isRefresh: boolean): Array&lt;DeviceInfo&gt;
335
336Enables the DSoftBus heartbeat mode to quickly bring offline trusted devices online and updates the list of online trusted devices.
337
338> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
339
340**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
341
342**System capability**: SystemCapability.DistributedHardware.DeviceManager
343
344**Parameters**
345
346| Name       | Type                              | Mandatory| Description                               |
347| ------------- | --------------------------------- | ---- | ---------------------------------- |
348|   isRefresh   | boolean                           | Yes  | Whether to enable the heartbeat mode and update the list of online trusted devices.     |
349
350**Return value**
351
352| Name                                    | Description           |
353| -------------------------------------- | ---------------- |
354| Array&lt;[DeviceInfo](#deviceinfo)&gt; | List of trusted devices obtained.|
355
356**Error codes**
357
358For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
359
360| ID| Error Message                                                        |
361| -------- | --------------------------------------------------------------- |
362| 11600101 | Failed to execute the function.                                 |
363
364**Example**
365
366For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
367  ```ts
368  import deviceManager from '@ohos.distributedHardware.deviceManager';
369  import { BusinessError } from '@ohos.base';
370
371  try {
372    let deviceInfoList: Array<deviceManager.DeviceInfo> = dmInstance.getTrustedDeviceListSync(true);
373  } catch (err) {
374    let e: BusinessError = err as BusinessError;
375    console.error("getTrustedDeviceListSync errCode:" + e.code + ",errMessage:" + e.message);
376  }
377  ```
378
379### getTrustedDeviceList<sup>8+</sup>
380
381getTrustedDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceInfo&gt;&gt;): void
382
383Obtains all trusted devices. This API uses an asynchronous callback to return the result.
384
385> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [getAvailableDeviceList](js-apis-distributedDeviceManager.md#getavailabledevicelist).
386
387**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
388
389**System capability**: SystemCapability.DistributedHardware.DeviceManager
390
391**Parameters**
392
393| Name      | Type                                    | Mandatory  | Description                   |
394| -------- | ---------------------------------------- | ---- | --------------------- |
395| callback | AsyncCallback&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | Yes   | Callback invoked to return the list of trusted devices.|
396
397**Example**
398
399For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
400  ```ts
401  import deviceManager from '@ohos.distributedHardware.deviceManager';
402  import { BusinessError } from '@ohos.base';
403
404  try {
405    dmInstance.getTrustedDeviceList((err: BusinessError, data: Array<deviceManager.DeviceInfo>) => {
406      if (err) {
407        console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
408        return;
409      }
410      console.log('get trusted device info: ' + JSON.stringify(data));
411    });
412  } catch (err) {
413    let e: BusinessError = err as BusinessError;
414    console.error("getTrustedDeviceList errCode:" + e.code + ",errMessage:" + e.message);
415  }
416  ```
417
418### getTrustedDeviceList<sup>8+</sup>
419
420getTrustedDeviceList(): Promise&lt;Array&lt;DeviceInfo&gt;&gt;
421
422Obtains all trusted devices. This API uses a promise to return the result.
423
424> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [getAvailableDeviceList](js-apis-distributedDeviceManager.md#getavailabledevicelist-1).
425
426**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
427
428**System capability**: SystemCapability.DistributedHardware.DeviceManager
429
430**Return value**
431
432| Type                                      | Description                   |
433| ---------------------------------------- | --------------------- |
434| Promise&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | Promise used to return the result.|
435
436**Example**
437
438For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
439  ```ts
440  import deviceManager from '@ohos.distributedHardware.deviceManager';
441  import { BusinessError } from '@ohos.base';
442
443  dmInstance.getTrustedDeviceList().then((data: Array<deviceManager.DeviceInfo>) => {
444    console.log('get trusted device info: ' + JSON.stringify(data));
445    }).catch((err: BusinessError) => {
446      console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
447  });
448  ```
449
450### getLocalDeviceInfoSync<sup>8+</sup>
451
452getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo)
453
454Obtains local device information synchronously.
455
456> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [getLocalDeviceNetworkId](js-apis-distributedDeviceManager.md#getlocaldevicenetworkid), [getLocalDeviceName](js-apis-distributedDeviceManager.md#getlocaldevicename), [getLocalDeviceType](js-apis-distributedDeviceManager.md#getlocaldevicetype), or [getLocalDeviceId](js-apis-distributedDeviceManager.md#getlocaldeviceid).
457
458**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
459
460**System capability**: SystemCapability.DistributedHardware.DeviceManager
461
462**Return value**
463
464| Name                     | Description             |
465| ------------------------- | ---------------- |
466| [DeviceInfo](#deviceinfo) | List of local devices obtained.|
467
468**Error codes**
469
470For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
471
472| ID| Error Message                                                       |
473| -------- | --------------------------------------------------------------- |
474| 11600101 | Failed to execute the function.                                 |
475
476**Example**
477
478For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
479  ```ts
480  import deviceManager from '@ohos.distributedHardware.deviceManager';
481  import { BusinessError } from '@ohos.base';
482
483  try {
484    let deviceInfo: deviceManager.DeviceInfo = dmInstance.getLocalDeviceInfoSync();
485  } catch (err) {
486    let e: BusinessError = err as BusinessError;
487    console.error("getLocalDeviceInfoSync errCode:" + e.code + ",errMessage:" + e.message);
488  }
489  ```
490
491### getLocalDeviceInfo<sup>8+</sup>
492
493getLocalDeviceInfo(callback:AsyncCallback&lt;DeviceInfo&gt;): void
494
495Obtains local device information. This API uses an asynchronous callback to return the result.
496
497> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [getLocalDeviceNetworkId](js-apis-distributedDeviceManager.md#getlocaldevicenetworkid), [getLocalDeviceName](js-apis-distributedDeviceManager.md#getlocaldevicename), [getLocalDeviceType](js-apis-distributedDeviceManager.md#getlocaldevicetype), or [getLocalDeviceId](js-apis-distributedDeviceManager.md#getlocaldeviceid).
498
499**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
500
501**System capability**: SystemCapability.DistributedHardware.DeviceManager
502
503**Parameters**
504
505| Name      | Type                                    | Mandatory  | Description       |
506| -------- | ---------------------------------------- | ---- | --------- |
507| callback | AsyncCallback&lt;[DeviceInfo](#deviceinfo)&gt; | Yes   | Callback invoked to return the local device information.|
508
509**Example**
510
511For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
512  ```ts
513  import deviceManager from '@ohos.distributedHardware.deviceManager';
514  import { BusinessError } from '@ohos.base';
515
516
517  try {
518    dmInstance.getLocalDeviceInfo((err: BusinessError, data: deviceManager.DeviceInfo) => {
519      if (err) {
520        console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
521        return;
522      }
523      console.log('get local device info: ' + JSON.stringify(data));
524    });
525  } catch (err) {
526    let e: BusinessError = err as BusinessError;
527    console.error("getLocalDeviceInfo errCode:" + e.code + ",errMessage:" + e.message);
528  }
529  ```
530
531### getLocalDeviceInfo<sup>8+</sup>
532
533getLocalDeviceInfo(): Promise&lt;DeviceInfo&gt;
534
535Obtains local device information. This API uses a promise to return the result.
536
537> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [getLocalDeviceNetworkId](js-apis-distributedDeviceManager.md#getlocaldevicenetworkid), [getLocalDeviceName](js-apis-distributedDeviceManager.md#getlocaldevicename), [getLocalDeviceType](js-apis-distributedDeviceManager.md#getlocaldevicetype), or [getLocalDeviceId](js-apis-distributedDeviceManager.md#getlocaldeviceid).
538
539**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
540
541**System capability**: SystemCapability.DistributedHardware.DeviceManager
542
543**Return value**
544
545| Type                                      | Description                   |
546| ---------------------------------------- | --------------------- |
547| Promise&lt;[DeviceInfo](#deviceinfo)&gt; | Promise used to return the result.|
548
549**Example**
550
551For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
552  ```ts
553  import deviceManager from '@ohos.distributedHardware.deviceManager';
554  import { BusinessError } from '@ohos.base';
555
556  dmInstance.getLocalDeviceInfo().then((data: deviceManager.DeviceInfo) => {
557    console.log('get local device info: ' + JSON.stringify(data));
558  }).catch((err: BusinessError) => {
559    console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
560  });
561  ```
562
563### getDeviceInfo<sup>10+</sup>
564
565getDeviceInfo(networkId: string, callback:AsyncCallback&lt;DeviceInfo&gt;): void
566
567Obtains the information about a specific device based on the network ID. This API uses an asynchronous callback to return the result.
568
569> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [getDeviceName](js-apis-distributedDeviceManager.md#getdevicename),[getDeviceType](js-apis-distributedDeviceManager.md#getdevicetype).
570
571**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
572
573**System capability**: SystemCapability.DistributedHardware.DeviceManager
574
575**Parameters**
576
577| Name      | Type                                    | Mandatory  | Description       |
578| -------- | ---------------------------------------- | ---- | --------- |
579| networkId| string                                   | Yes  | Network ID of the device.|
580| callback | AsyncCallback&lt;[DeviceInfo](#deviceinfo)&gt; | Yes   | Callback invoked to return the information about the specified device.|
581
582**Example**
583
584For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
585  ```ts
586  import deviceManager from '@ohos.distributedHardware.deviceManager';
587  import { BusinessError } from '@ohos.base';
588
589  try {
590    // Network ID of the device, which can be obtained from the trusted device list
591    let networkId = "xxxxxxx";
592    dmInstance.getDeviceInfo(networkId, (err: BusinessError, data: deviceManager.DeviceInfo) => {
593      if (err) {
594        console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
595        return;
596      }
597      console.log('get device info: ' + JSON.stringify(data));
598    });
599  } catch (err) {
600    let e: BusinessError = err as BusinessError;
601    console.error("getDeviceInfo errCode:" + e.code + ",errMessage:" + e.message);
602  }
603  ```
604
605### getDeviceInfo<sup>10+</sup>
606
607getDeviceInfo(networkId: string): Promise&lt;DeviceInfo&gt;
608
609Obtains the information about a specific device based on the network ID. This API uses a promise to return the result.
610
611> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [getDeviceName](js-apis-distributedDeviceManager.md#getdevicename) or [getDeviceType](js-apis-distributedDeviceManager.md#getdevicetype).
612
613**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
614
615**System capability**: SystemCapability.DistributedHardware.DeviceManager
616
617**Parameters**
618
619| Name  | Type                                    | Mandatory| Description       |
620| -------- | ---------------------------------------- | ---- | --------- |
621| networkId| string                                   | Yes  | Network ID of the device.|
622
623**Return value**
624
625| Type                                      | Description                   |
626| ---------------------------------------- | --------------------- |
627| Promise&lt;[DeviceInfo](#deviceinfo)&gt; | Promise used to return the result.|
628
629**Example**
630
631For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
632  ```ts
633  import deviceManager from '@ohos.distributedHardware.deviceManager';
634  import { BusinessError } from '@ohos.base';
635
636  // Network ID of the device, which can be obtained from the trusted device list
637  let networkId = "xxxxxxx";
638  dmInstance.getDeviceInfo(networkId).then((data: deviceManager.DeviceInfo) => {
639    console.log('get device info: ' + JSON.stringify(data));
640  }).catch((err: BusinessError) => {
641    console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
642  });
643  ```
644
645### startDeviceDiscovery<sup>8+</sup>
646
647startDeviceDiscovery(subscribeInfo: SubscribeInfo): void
648
649Starts to discover peripheral devices. The discovery process automatically stops when 2 minutes have elapsed. A maximum of 99 devices can be discovered.
650
651> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [startDiscovering](js-apis-distributedDeviceManager.md#startdiscovering).
652
653**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
654
655**System capability**: SystemCapability.DistributedHardware.DeviceManager
656
657**Parameters**
658
659| Name           | Type                      | Mandatory| Description   |
660| ------------- | ------------------------------- | ---- | ----- |
661| subscribeInfo | [SubscribeInfo](#subscribeinfo) | Yes  | Subscription information.|
662
663**Error codes**
664
665For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
666
667| ID| Error Message                                                       |
668| -------- | --------------------------------------------------------------- |
669| 11600101 | Failed to execute the function.                                 |
670| 11600104 | Discovery invalid.                                              |
671
672**Example**
673
674For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
675  ```ts
676  import { BusinessError } from '@ohos.base';
677
678  interface SubscribeInfo {
679    subscribeId: number;
680    mode: number, // Active discovery
681    medium: number,  // Automatic. Multiple media can be used for device discovery.
682    freq: number,    // High frequency
683    isSameAccount: boolean;
684    isWakeRemote: boolean;
685    capability: number;
686  }
687
688  // Automatically generate a unique subscription ID.
689  let subscribeId = Math.floor(Math.random() * 10000 + 1000);
690  let subscribeInfo: SubscribeInfo = {
691    subscribeId: subscribeId,
692    mode: 0xAA, // Active discovery
693    medium: 0,  // Automatic. Multiple media can be used for device discovery.
694    freq: 2,    // High frequency
695    isSameAccount: false,
696    isWakeRemote: false,
697    capability: 1
698  };
699  try {
700    dmInstance.startDeviceDiscovery(subscribeInfo); // The deviceFound callback is called to notify the application when a device is discovered.
701  } catch (err) {
702    let e: BusinessError = err as BusinessError;
703    console.error("startDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
704  }
705  ```
706
707### startDeviceDiscovery<sup>9+</sup>
708
709startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void
710
711Starts to discover peripheral devices and filters discovered devices. The discovery process automatically stops when 2 minutes have elapsed. A maximum of 99 devices can be discovered.
712
713> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [startDiscovering](js-apis-distributedDeviceManager.md#startdiscovering).
714
715**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
716
717**System capability**: SystemCapability.DistributedHardware.DeviceManager
718
719**Parameters**
720
721| Name           | Type                      | Mandatory  | Description   |
722| ------------- | ------------------------------- | ---- | -----  |
723| subscribeInfo | [SubscribeInfo](#subscribeinfo) | Yes  | Subscription information.|
724| filterOptions | string                          | No  | Options for filtering discovered devices. Optional. The default value is **undefined**, which indicates discovery of offline devices.|
725
726**Error codes**
727
728For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
729
730| ID| Error Message                                                       |
731| -------- | --------------------------------------------------------------- |
732| 11600101 | Failed to execute the function.                                 |
733| 11600104 | Discovery invalid.                                              |
734
735**Example**
736
737For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
738  ```ts
739  import { BusinessError } from '@ohos.base';
740
741  interface Filters {
742    type: string;
743    value: number;
744  }
745
746  interface FilterOptions {
747    filter_op: string, // Optional. The default value is OR.
748    filters: Filters[];
749  }
750
751  interface SubscribeInfo {
752    subscribeId: number;
753    mode: number, // Active discovery
754    medium: number,  // Automatic. Multiple media can be used for device discovery.
755    freq: number,    // High frequency
756    isSameAccount: boolean;
757    isWakeRemote: boolean;
758    capability: number;
759  }
760
761  // Automatically generate a unique subscription ID.
762  let subscribeId = Math.floor(Math.random() * 10000 + 1000);
763  let subscribeInfo: SubscribeInfo = {
764    subscribeId: subscribeId,
765    mode: 0xAA, // Active discovery
766    medium: 0,  // Automatic. Multiple media can be used for device discovery.
767    freq: 2,    // High frequency
768    isSameAccount: false,
769    isWakeRemote: false,
770    capability: 1
771  };
772
773  let filters: Filters[] = [
774    {
775        type: "range",
776        value: 50 // Filter discovered devices based on the distance (in cm).
777    }
778  ];
779
780  let filterOptions: FilterOptions = {
781    filter_op: "OR", // Optional. The default value is OR.
782    filters: filters
783  };
784  try {
785    dmInstance.startDeviceDiscovery(subscribeInfo, JSON.stringify(filterOptions)); // The deviceFound callback is invoked to notify the application when a device is discovered.
786  } catch (err) {
787    let e: BusinessError = err as BusinessError;
788    console.error("startDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
789  }
790  ```
791
792### stopDeviceDiscovery
793
794stopDeviceDiscovery(subscribeId: number): void
795
796Stops device discovery.
797
798> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [stopDiscovering](js-apis-distributedDeviceManager.md#stopdiscovering).
799
800**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
801
802**System capability**: SystemCapability.DistributedHardware.DeviceManager
803
804**Parameters**
805
806| Name         | Type  | Mandatory  | Description   |
807| ----------- | ------ | ---- | ----- |
808| subscribeId | number | Yes   | Subscription ID.|
809
810**Error codes**
811
812For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
813
814| ID| Error Message                                                       |
815| -------- | --------------------------------------------------------------- |
816| 11600101 | Failed to execute the function.                                 |
817
818**Example**
819
820For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
821  ```ts
822  import { BusinessError } from '@ohos.base';
823
824  try {
825    // stopDeviceDiscovery and startDeviceDiscovery must be used in pairs, and the input parameter **subscribeId** passed in them must be the same.
826    let subscribeId = 12345;
827    dmInstance.stopDeviceDiscovery(subscribeId);
828  } catch (err) {
829    let e: BusinessError = err as BusinessError;
830    console.error("stopDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
831  }
832  ```
833
834### publishDeviceDiscovery<sup>9+</sup>
835
836publishDeviceDiscovery(publishInfo: PublishInfo): void
837
838Publishes device information for discovery purposes. The publish process automatically stops when 2 minutes have elapsed.
839
840> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
841
842**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
843
844**System capability**: SystemCapability.DistributedHardware.DeviceManager
845
846**Parameters**
847
848| Name         | Type                       | Mandatory| Description   |
849| ------------- | ------------------------------- | ---- | ----- |
850| publishInfo   | [PublishInfo](#publishinfo)     | Yes  | Device information to publish.|
851
852**Error codes**
853
854For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
855
856| ID| Error Message                                                       |
857| -------- | --------------------------------------------------------------- |
858| 11600101 | Failed to execute the function.                                 |
859| 11600105 | Publish invalid.                                                |
860
861**Example**
862
863For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
864  ```ts
865  import { BusinessError } from '@ohos.base';
866
867  interface PublishInfo {
868    publishId: number;
869    mode: number, // Active discovery
870    freq: number,    // High frequency
871    ranging: boolean // Whether the device supports reporting the distance to the discovery initiator.
872  };
873
874  // Automatically generate a unique subscription ID.
875  let publishId = Math.floor(Math.random() * 10000 + 1000);
876  let publishInfo: PublishInfo = {
877    publishId: publishId,
878    mode: 0xAA, // Active discovery
879    freq: 2,    // High frequency
880    ranging: true  // The device supports reporting the distance to the discovery initiator.
881  };
882
883  try {
884    dmInstance.publishDeviceDiscovery(publishInfo); // A callback is invoked to notify the application when the device information is published.
885  } catch (err) {
886    let e: BusinessError = err as BusinessError;
887    console.error("publishDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
888  }
889  ```
890
891### unPublishDeviceDiscovery<sup>9+</sup>
892
893unPublishDeviceDiscovery(publishId: number): void
894
895Stops publishing device information.
896
897> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
898
899**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
900
901**System capability**: SystemCapability.DistributedHardware.DeviceManager
902
903**Parameters**
904
905| Name       | Type| Mandatory| Description |
906| ----------- | -------- | ---- | ----- |
907| publishId   | number   | Yes  | Publish ID.|
908
909**Error codes**
910
911For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
912
913| ID| Error Message                                                       |
914| -------- | --------------------------------------------------------------- |
915| 11600101 | Failed to execute the function.                                 |
916
917**Example**
918
919For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
920  ```ts
921  import { BusinessError } from '@ohos.base';
922
923  try {
924    // unPublishDeviceDiscovery and publishDeviceDiscovery must be used in pairs, and the input parameter **publishId** passed in them must be the same.
925    let publishId = 12345;
926    dmInstance.unPublishDeviceDiscovery(publishId);
927  } catch (err) {
928    let e: BusinessError = err as BusinessError;
929    console.error("unPublishDeviceDiscovery errCode:" + e.code + ",errMessage:" + e.message);
930  }
931  ```
932
933### authenticateDevice
934
935authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback&lt;{deviceId: string, pinToken ?: number}&gt;): void
936
937Authenticates a device.
938
939> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [bindTarget](js-apis-distributedDeviceManager.md#bindtarget).
940
941**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
942
943**System capability**: SystemCapability.DistributedHardware.DeviceManager
944
945**Parameters**
946
947| Name        | Type                                    | Mandatory  | Description     |
948| ---------- | ---------------------------------------- | ---- | ------- |
949| deviceInfo | [DeviceInfo](#deviceinfo)                | Yes   | Device information.  |
950| authParam  | [AuthParam](#authparam)                  | Yes   | Authentication parameter.  |
951| callback   | AsyncCallback&lt;{deviceId:&nbsp;string,&nbsp;pinToken&nbsp;?:&nbsp;number}&gt; | Yes   | Callback invoked to return the authentication result.|
952
953**Example**
954
955For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
956  ```ts
957  import { BusinessError } from '@ohos.base';
958
959  class Data {
960    deviceId: string = "";
961    pinToken?: number = 0;
962  }
963
964  interface DeviceInfo {
965    deviceId: string;
966    deviceName: string;
967    deviceType: number;
968    networkId: string;
969    range: number;
970  };
971
972  interface ExtraInfo {
973    targetPkgName: string;
974    appName: string;
975    appDescription: string;
976    business: string;
977  }
978
979  interface AuthParam {
980    authType: number,// Authentication type. The value 1 means PIN authentication.
981    extraInfo: ExtraInfo;
982  }
983
984  // Information about the device to authenticate. The information can be obtained from the device discovery result.
985  let deviceInfo: deviceManager.DeviceInfo = {
986    deviceId: "XXXXXXXX",
987    deviceName: "",
988    deviceType: 0x0E,
989    networkId: "xxxxxxx",
990    range: 0,
991    authForm: 0
992  };
993  let extraInfo: ExtraInfo = {
994    targetPkgName: 'ohos.samples.xxx',
995    appName: 'xxx',
996    appDescription: 'xxx',
997    business: '0'
998  };
999  let authParam: AuthParam = {
1000    authType: 1,// Authentication type. The value 1 means no account PIN authentication.
1001    extraInfo: extraInfo
1002  };
1003
1004  try {
1005    dmInstance.authenticateDevice(deviceInfo, authParam, (err: BusinessError, data: Data) => {
1006      if (err) {
1007        console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
1008        return;
1009      }
1010      console.info("authenticateDevice result:" + JSON.stringify(data));
1011      let token = data.pinToken;
1012    });
1013  } catch (err) {
1014    let e: BusinessError = err as BusinessError;
1015    console.error("authenticateDevice errCode:" + e.code + ",errMessage:" + e.message);
1016  }
1017  ```
1018
1019### unAuthenticateDevice<sup>8+</sup>
1020
1021unAuthenticateDevice(deviceInfo: DeviceInfo): void
1022
1023Deauthenticates a device.
1024
1025> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [unbindTarget](js-apis-distributedDeviceManager.md#unbindtarget).
1026
1027**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1028
1029**System capability**: SystemCapability.DistributedHardware.DeviceManager
1030
1031**Parameters**
1032
1033| Name        | Type                     | Mandatory  | Description   |
1034| ---------- | ------------------------- | ---- | ----- |
1035| deviceInfo | [DeviceInfo](#deviceinfo) | Yes   | Device information.|
1036
1037**Error codes**
1038
1039For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
1040
1041| ID| Error Message                                                       |
1042| -------- | --------------------------------------------------------------- |
1043| 11600101 | Failed to execute the function.                                 |
1044
1045**Example**
1046
1047For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1048  ```ts
1049  import { BusinessError } from '@ohos.base';
1050
1051  interface DeviceInfo {
1052    deviceId: string;
1053    deviceName: string;
1054    deviceType: number;
1055    networkId: string;
1056    range: number;
1057  }
1058
1059  try {
1060    let deviceInfo: deviceManager.DeviceInfo = {
1061      deviceId: "XXXXXXXX",
1062      deviceName: "",
1063      deviceType: 0x0E,
1064      networkId: "xxxxxxx",
1065      range: 0,
1066      authForm: 0
1067    };
1068    dmInstance.unAuthenticateDevice(deviceInfo);
1069  } catch (err) {
1070    let e: BusinessError = err as BusinessError;
1071    console.error("unAuthenticateDevice errCode:" + e.code + ",errMessage:" + e.message);
1072  }
1073  ```
1074
1075### verifyAuthInfo
1076
1077verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback&lt;{deviceId: string, level: number}&gt;): void
1078
1079Verifies authentication information.
1080
1081> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
1082
1083**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1084
1085**System capability**: SystemCapability.DistributedHardware.DeviceManager
1086
1087**Parameters**
1088
1089| Name      | Type                                    | Mandatory  | Description     |
1090| -------- | ---------------------------------------- | ---- | ------- |
1091| authInfo | [AuthInfo](#authinfo)                    | Yes   | Authentication information.  |
1092| callback | AsyncCallback&lt;{deviceId:&nbsp;string,&nbsp;level:&nbsp;number}&gt; | Yes   | Callback invoked to return the verification result.|
1093
1094**Example**
1095
1096For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1097  ```ts
1098  import { BusinessError } from '@ohos.base';
1099
1100  interface ExtraInfo {
1101    authType: number;
1102    token: numbe;
1103  }
1104
1105  interface AuthInfo {
1106    authType: number;
1107    token: number;
1108    extraInfo: ExtraInf;
1109  }
1110
1111  class Data {
1112    deviceId: string = "";
1113    level: number = 0;
1114  }
1115
1116  let extraInfo: ExtraInfo = {
1117    authType: 0,
1118    token: 0
1119  };
1120
1121  let authInfo: AuthInfo = {
1122    authType: 1,
1123    token: 123456,
1124    extraInfo: extraInfo
1125  };
1126  try {
1127    dmInstance.verifyAuthInfo(authInfo, (err: BusinessError, data: Data) => {
1128      if (err) {
1129        console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
1130        return;
1131      }
1132    console.info("verifyAuthInfo result:" + JSON.stringify(data));
1133    });
1134  } catch (err) {
1135    let e: BusinessError = err as BusinessError;
1136    console.error("verifyAuthInfo errCode:" + e.code + ",errMessage:" + e.message);
1137  }
1138  ```
1139
1140### setUserOperation<sup>9+</sup>
1141
1142setUserOperation(operateAction: number, params: string): void;
1143
1144Sets a user operation.
1145
1146> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [replyUiAction](js-apis-distributedDeviceManager.md#replyuiaction).
1147
1148**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1149
1150**System capability**: SystemCapability.DistributedHardware.DeviceManager
1151
1152**Parameters**
1153
1154| Name      | Type           | Mandatory | Description               |
1155| ------------- | --------------- | ---- | ------------------- |
1156| operateAction | number          | Yes   | User operation.      |
1157| params        | string          | Yes   | Input parameters of the user.|
1158
1159**Example**
1160
1161For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1162  ```ts
1163  import { BusinessError } from '@ohos.base';
1164
1165 try {
1166    /*
1167      operateAction = 0 - Grant the permission.
1168      operateAction = 1 - Revoke the permission.
1169      operateAction = 2 - The user operation in the permission request dialog box times out.
1170      operateAction = 3 - Cancel the display of the PIN box.
1171      operateAction = 4 - Cancel the display of the PIN input box.
1172      operateAction = 5 - Confirm the input in the PIN input box.
1173    */
1174    let operation = 0;
1175    dmInstance.setUserOperation(operation, "extra");
1176  } catch (err) {
1177    let e: BusinessError = err as BusinessError;
1178    console.error("setUserOperation errCode:" + e.code + ",errMessage:" + e.message);
1179  }
1180  ```
1181
1182### requestCredentialRegisterInfo<sup>10+</sup>
1183
1184requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{registerInfo: string}>): void;
1185
1186Obtains the registration information of the credential.
1187
1188> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
1189
1190**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1191
1192**System capability**: SystemCapability.DistributedHardware.DeviceManager
1193
1194**Parameters**
1195
1196| Name      | Type           | Mandatory | Description               |
1197| ------------- | --------------- | ---- | ------------------- |
1198| requestInfo   | string          | Yes   | Request credential information.      |
1199| callback      | AsyncCallback<{registerInfo: string}>         | Yes   | Callback invoked to return the credential registration information.|
1200
1201**Example**
1202
1203For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1204  ```ts
1205  import { BusinessError } from '@ohos.base';
1206
1207  interface CredentialInfo {
1208    version: string;
1209    userId: string;
1210  }
1211
1212  class Data {
1213    registerInfo: string = "";
1214  }
1215
1216  let credentialInfo: CredentialInfo = {
1217    version: "1.2.3",
1218    userId: "123"
1219  };
1220  try {
1221    let jsonCredentialInfo = JSON.stringify(credentialInfo);
1222    dmInstance.requestCredentialRegisterInfo(jsonCredentialInfo, (err: BusinessError, data: Data) => {
1223      if (data) {
1224        console.info("requestCredentialRegisterInfo result:" + JSON.stringify(data));
1225      } else {
1226        console.info("requestCredentialRegisterInfo result: data is null");
1227      }
1228    });
1229  } catch (err) {
1230    let e: BusinessError = err as BusinessError;
1231    console.error("requestCredentialRegisterInfo err:" + e.code + "," + e.message);
1232  }
1233  ```
1234
1235### importCredential<sup>10+</sup>
1236
1237importCredential(credentialInfo: string, callback: AsyncCallback<{resultInfo: string}>): void;
1238
1239Imports credential information.
1240
1241> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
1242
1243**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1244
1245**System capability**: SystemCapability.DistributedHardware.DeviceManager
1246
1247**Parameters**
1248
1249| Name      | Type           | Mandatory | Description               |
1250| ------------- | --------------- | ---- | ------------------- |
1251| credentialInfo| string          | Yes   | Credential information to import.      |
1252| callback      | AsyncCallback<{resultInfo: string}>           | Yes   | Callback invoked to return the result.|
1253
1254**Example**
1255
1256For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1257  ```ts
1258  import { BusinessError } from '@ohos.base';
1259
1260  class Data {
1261    resultInfo: string = "";
1262  }
1263
1264  interface CredentialData {
1265    credentialType: number;
1266    credentialId: string;
1267    serverPk: string;
1268    pkInfoSignature : string;
1269    pkInfo: string;
1270    authCode: string;
1271    peerDeviceId: string;
1272  }
1273
1274  interface CredentialInfo {
1275    processType: number;
1276    authType: number;
1277    userId: string;
1278    deviceId: string;
1279    version: string;
1280    devicePk : string;
1281    credentialData : CredentialData;
1282  }
1283
1284  let credentialData: CredentialData = {
1285    credentialType: 2,
1286    credentialId: "102",
1287    serverPk: "3059301306072A8648CE3D020106082A8648CE3D03",
1288    pkInfoSignature : "30440220490BCB4F822004C9A76AB8D97F80041FC0E",
1289    pkInfo: "",
1290    authCode: "",
1291    peerDeviceId: ""
1292  };
1293
1294
1295  let credentialInfo: CredentialInfo = {
1296    processType: 1,
1297    authType: 1,
1298    userId: "123",
1299    deviceId: "aaa",
1300    version: "1.2.3",
1301    devicePk : "0000",
1302    credentialData : credentialData
1303  };
1304
1305  try {
1306    let jsonCredentialInfo = JSON.stringify(credentialInfo);
1307    dmInstance.importCredential(jsonCredentialInfo, (err: BusinessError, data: Data) => {
1308      if (data) {
1309        console.info("importCredential result:" + JSON.stringify(data));
1310      } else {
1311        console.info("importCredential result: data is null");
1312      }
1313    });
1314  } catch (err) {
1315    let e: BusinessError = err as BusinessError;
1316    console.error("importCredential err:" + e.code + "," + e.message);
1317  }
1318  ```
1319
1320### deleteCredential<sup>10+</sup>
1321
1322deleteCredential(queryInfo: string, callback: AsyncCallback<{resultInfo: string}>): void;
1323
1324Deletes credential information.
1325
1326> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
1327
1328**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1329
1330**System capability**: SystemCapability.DistributedHardware.DeviceManager
1331
1332**Parameters**
1333
1334| Name      | Type           | Mandatory | Description               |
1335| ------------- | --------------- | ---- | ------------------- |
1336| queryInfo     | string          | Yes   | Credential information to delete.      |
1337| callback      | AsyncCallback<{resultInfo: string}>           | Yes   | Callback invoked to return the result.|
1338
1339**Example**
1340
1341For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1342  ```ts
1343  import { BusinessError } from '@ohos.base';
1344
1345  class Data {
1346    resultInfo: string = "";
1347  }
1348
1349  interface QueryInfo {
1350    processType: number;
1351    authType: number;
1352    userId: string;
1353  }
1354
1355  let queryInfo: QueryInfo = {
1356    processType: 1,
1357    authType: 1,
1358    userId: "123"
1359  };
1360
1361  try {
1362    let jsonQueryInfo = JSON.stringify(queryInfo);
1363    dmInstance.deleteCredential(jsonQueryInfo, (err: BusinessError, data: Data) => {
1364      if (data) {
1365        console.info("deleteCredential result:" + JSON.stringify(data));
1366      } else {
1367        console.info("deleteCredential result: data is null");
1368      }
1369    });
1370  } catch (err) {
1371    let e: BusinessError = err as BusinessError;
1372    console.error("deleteCredential err:" + e.code + "," + e.message);
1373  }
1374  ```
1375
1376### on('uiStateChange')<sup>9+</sup>
1377
1378on(type: 'uiStateChange', callback: Callback&lt;{ param: string}&gt;): void;
1379
1380Subscribes to UI state changes.
1381
1382> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [on('replyResult')](js-apis-distributedDeviceManager.md#onreplyresult).
1383
1384**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1385
1386**System capability**: SystemCapability.DistributedHardware.DeviceManager
1387
1388**Parameters**
1389
1390| Name     | Type                            | Mandatory| Description                           |
1391| -------- | ------------------------------------ | ---- | ------------------------------ |
1392| type     | string                                | Yes | Event type. The value **'uiStateChange'** indicates UI state changes. |
1393| callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | Yes | Callback invoked to return the UI state.       |
1394
1395**Example**
1396
1397For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1398  ```ts
1399  import { BusinessError } from '@ohos.base';
1400
1401  class Data {
1402    param: string = "";
1403  }
1404
1405  interface TmpStr {
1406    verifyFailed: boolean;
1407  }
1408
1409  try {
1410    dmInstance.on('uiStateChange', (data: Data) => {
1411      console.log("uiStateChange executed, dialog closed" + JSON.stringify(data));
1412      let tmpStr: TmpStr = JSON.parse(data.param);
1413      let isShow = tmpStr.verifyFailed;
1414      console.log("uiStateChange executed, dialog closed" + isShow);
1415    });
1416  } catch (err) {
1417    let e: BusinessError = err as BusinessError;
1418    console.error("uiStateChange errCode:" + e.code + ",errMessage:" + e.message);
1419  }
1420  ```
1421
1422### off('uiStateChange')<sup>9+</sup>
1423
1424off(type: 'uiStateChange', callback?: Callback&lt;{ param: string}&gt;): void;
1425
1426Unsubscribes from UI state changes.
1427
1428> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [off('replyResult')](js-apis-distributedDeviceManager.md#offreplyresult).
1429
1430**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1431
1432**System capability**: SystemCapability.DistributedHardware.DeviceManager
1433
1434**Parameters**
1435
1436| Name     | Type                             | Mandatory| Description                           |
1437| -------- | ------------------------------------- | ---- | ------------------------------ |
1438| type     | string                                | Yes  | Event type. The value **'uiStateChange'** indicates UI state changes. |
1439| callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | No  | Callback to unregister. |
1440
1441**Example**
1442
1443For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1444  ```ts
1445  import { BusinessError } from '@ohos.base';
1446
1447  try {
1448    dmInstance.off('uiStateChange');
1449  } catch (err) {
1450    let e: BusinessError = err as BusinessError;
1451    console.error("uiStateChange errCode:" + e.code + ",errMessage:" + e.message);
1452  }
1453  ```
1454
1455### on('deviceStateChange')
1456
1457on(type: 'deviceStateChange',  callback: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void
1458
1459Subscribes to device state changes.
1460
1461> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [on('deviceStateChange')](js-apis-distributedDeviceManager.md#ondevicestatechange).
1462
1463**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1464
1465**System capability**: SystemCapability.DistributedHardware.DeviceManager
1466
1467**Parameters**
1468
1469| Name      | Type                                    | Mandatory  | Description                            |
1470| -------- | ---------------------------------------- | ---- | ------------------------------ |
1471| type     | string                                   | Yes   | Event type. The value **'deviceStateChange'** indicates device state changes. |
1472| callback | Callback&lt;{&nbsp;action:&nbsp;[DeviceStateChangeAction](#devicestatechangeaction),&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | Yes   | Callback invoked to return the device information and state.     |
1473
1474**Example**
1475
1476For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1477  ```ts
1478  import deviceManager from '@ohos.distributedHardware.deviceManager';
1479  import { BusinessError } from '@ohos.base';
1480
1481  class Data {
1482    action: deviceManager.DeviceStateChangeAction = 0;
1483    device: deviceManager.DeviceInfo = {
1484      deviceId: "",
1485      deviceName: "",
1486      deviceType: 0,
1487      networkId: "",
1488      range: 0,
1489      authForm:0
1490    };
1491  }
1492
1493  try {
1494    dmInstance.on('deviceStateChange', (data: Data) => {
1495      console.info("deviceStateChange on:" + JSON.stringify(data));
1496    });
1497  } catch (err) {
1498    let e: BusinessError = err as BusinessError;
1499    console.error("deviceStateChange errCode:" + e.code + ",errMessage:" + e.message);
1500  }
1501  ```
1502
1503### off('deviceStateChange')
1504
1505off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void
1506
1507Unsubscribes from device state changes.
1508
1509> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [off('deviceStateChange')](js-apis-distributedDeviceManager.md#offdevicestatechange).
1510
1511**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1512
1513**System capability**: SystemCapability.DistributedHardware.DeviceManager
1514
1515**Parameters**
1516
1517| Name      | Type                                    | Mandatory  | Description                         |
1518| -------- | ---------------------------------------- | ---- | --------------------------- |
1519| type     | string                                   | Yes   | Event type. The value **'deviceStateChange'** indicates device state changes.      |
1520| callback | Callback&lt;{&nbsp;action:&nbsp;[DeviceStateChangeAction](#devicestatechangeaction),&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | No   | Callback to unregister. |
1521
1522**Example**
1523
1524For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1525  ```ts
1526  import deviceManager from '@ohos.distributedHardware.deviceManager';
1527  import { BusinessError } from '@ohos.base';
1528
1529  class Data {
1530    action: deviceManager.DeviceStateChangeAction = 0;
1531    device: deviceManager.DeviceInfo = {
1532      deviceId: "",
1533      deviceName: "",
1534      deviceType: 0,
1535      networkId: "",
1536      range: 0,
1537      authForm:0
1538    };
1539  }
1540
1541  try {
1542    dmInstance.off('deviceStateChange', (data: Data) => {
1543      console.info('deviceStateChange' + JSON.stringify(data));
1544    });
1545  } catch (err) {
1546    let e: BusinessError = err as BusinessError;
1547    console.error("deviceStateChange errCode:" + e.code + ",errMessage:" + e.message);
1548  }
1549  ```
1550
1551### on('deviceFound')
1552
1553on(type: 'deviceFound', callback: Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt;): void
1554
1555Subscribes to device discovery events.
1556
1557> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [on('discoverSuccess')](js-apis-distributedDeviceManager.md#ondiscoversuccess).
1558
1559**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1560
1561**System capability**: SystemCapability.DistributedHardware.DeviceManager
1562
1563**Parameters**
1564
1565| Name      | Type                                    | Mandatory  | Description                        |
1566| -------- | ---------------------------------------- | ---- | -------------------------- |
1567| type     | string                                   | Yes   | Event type. The value **'deviceFound'** indicates that a device is discovered. |
1568| callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | Yes   | Callback invoked when a device is discovered. |
1569
1570**Example**
1571
1572For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1573  ```ts
1574  import deviceManager from '@ohos.distributedHardware.deviceManager';
1575  import { BusinessError } from '@ohos.base';
1576
1577  class Data {
1578    subscribeId: number = 0;
1579    device: deviceManager.DeviceInfo = {
1580      deviceId: "",
1581      deviceName: "",
1582      deviceType: 0,
1583      networkId: "",
1584      range: 0,
1585      authForm:0
1586    };
1587  }
1588
1589  try {
1590    dmInstance.on('deviceFound', (data: Data) => {
1591      console.info("deviceFound:" + JSON.stringify(data));
1592    });
1593  } catch (err) {
1594    let e: BusinessError = err as BusinessError;
1595    console.error("deviceFound errCode:" + e.code + ",errMessage:" + e.message);
1596  }
1597  ```
1598
1599### off('deviceFound')
1600
1601off(type: 'deviceFound', callback?: Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt;): void
1602
1603Unsubscribes from device discovery events.
1604
1605> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [off('discoverSuccess')](js-apis-distributedDeviceManager.md#offdiscoversuccess).
1606
1607**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1608
1609**System capability**: SystemCapability.DistributedHardware.DeviceManager
1610
1611**Parameters**
1612
1613| Name      | Type                                    | Mandatory  | Description                         |
1614| -------- | ---------------------------------------- | ---- | --------------------------- |
1615| type     | string                                   | Yes   | Event type. The value **'deviceFound'** indicates that a device is discovered. |
1616| callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | No   | Callback to unregister. |
1617
1618**Example**
1619
1620For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1621  ```ts
1622  import deviceManager from '@ohos.distributedHardware.deviceManager';
1623  import { BusinessError } from '@ohos.base';
1624
1625  class Data {
1626    subscribeId: number = 0;
1627    device: deviceManager.DeviceInfo = {
1628      deviceId: "",
1629      deviceName: "",
1630      deviceType: 0,
1631      networkId: "",
1632      range: 0,
1633      authForm:0
1634    };
1635  }
1636
1637  try {
1638    dmInstance.off('deviceFound', (data: Data) => {
1639      console.info('deviceFound' + JSON.stringify(data));
1640    });
1641  } catch (err) {
1642    let e: BusinessError = err as BusinessError;
1643    console.error("deviceFound errCode:" + e.code + ",errMessage:" + e.message);
1644  }
1645  ```
1646
1647### on('discoverFail')
1648
1649on(type: 'discoverFail', callback: Callback&lt;{ subscribeId: number, reason: number }&gt;): void
1650
1651Subscribes to device discovery failures.
1652
1653> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [on('discoverFailure')](js-apis-distributedDeviceManager.md#ondiscoverfailure).
1654
1655**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1656
1657**System capability**: SystemCapability.DistributedHardware.DeviceManager
1658
1659**Parameters**
1660
1661| Name      | Type                                    | Mandatory  | Description                            |
1662| -------- | ---------------------------------------- | ---- | ------------------------------ |
1663| type     | string                                   | Yes   | Event type. The value **'discoverFail'** indicates a failure in discovering devices. |
1664| callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | Yes   | Callback invoked when a device fails to be discovered. |
1665
1666**Example**
1667
1668For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1669  ```ts
1670  import { BusinessError } from '@ohos.base';
1671
1672  class Data {
1673    subscribeId: number = 0;
1674    reason: number = 0;
1675  }
1676
1677  try {
1678    dmInstance.on('discoverFail', (data: Data) => {
1679      console.info("discoverFail on:" + JSON.stringify(data));
1680    });
1681  } catch (err) {
1682    let e: BusinessError = err as BusinessError;
1683    console.error("discoverFail errCode:" + e.code + ",errMessage:" + e.message);
1684  }
1685  ```
1686
1687### off('discoverFail')
1688
1689off(type: 'discoverFail', callback?: Callback&lt;{ subscribeId: number, reason: number }&gt;): void
1690
1691Unsubscribes from device discovery failures.
1692
1693> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [off('discoverFailure')](js-apis-distributedDeviceManager.md#offdiscoverfailure).
1694
1695**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1696
1697**System capability**: SystemCapability.DistributedHardware.DeviceManager
1698
1699**Parameters**
1700
1701| Name      | Type                                    | Mandatory  | Description               |
1702| -------- | ---------------------------------------- | ---- | ----------------- |
1703| type     | string                                   | Yes   | Event type. The value **'discoverFail'** indicates a failure in discovering devices. |
1704| callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | No   | Callback to unregister. |
1705
1706**Example**
1707
1708For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1709  ```ts
1710  import { BusinessError } from '@ohos.base';
1711
1712  class Data {
1713    subscribeId: number = 0;
1714    reason: number = 0;
1715  }
1716
1717  try {
1718    dmInstance.off('discoverFail', (data: Data) => {
1719      console.info('discoverFail' + JSON.stringify(data));
1720    });
1721  } catch (err) {
1722    let e: BusinessError = err as BusinessError;
1723    console.error("discoverFail errCode:" + e.code + ",errMessage:" + e.message);
1724  }
1725  ```
1726
1727### on('publishSuccess')<sup>9+</sup>
1728
1729on(type: 'publishSuccess', callback: Callback&lt;{ publishId: number }&gt;): void
1730
1731Subscribes to the **'publishSuccess'** event. The application will be notified when the information of a device is published.
1732
1733> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
1734
1735**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1736
1737**System capability**: SystemCapability.DistributedHardware.DeviceManager
1738
1739**Parameters**
1740
1741| Name    | Type                                | Mandatory| Description                      |
1742| -------- | ---------------------------------------- | ---- | -------------------------- |
1743| type     | string                                   | Yes  | Event type. The value **'publishSuccess'** indicates that the information of a device is published |
1744| callback | Callback&lt;{&nbsp;publishId:&nbsp;number&nbsp;}&gt;    | Yes  | Callback invoked to return the publish ID.              |
1745
1746
1747**Example**
1748
1749For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1750  ```ts
1751  import { BusinessError } from '@ohos.base';
1752
1753  class Data {
1754    publishId: number = 0;
1755  }
1756
1757  try {
1758    dmInstance.on('publishSuccess', (data: Data) => {
1759      console.info("publishSuccess:" + JSON.stringify(data));
1760    });
1761  } catch (err) {
1762    let e: BusinessError = err as BusinessError;
1763    console.error("publishSuccess errCode:" + e.code + ",errMessage:" + e.message);
1764  }
1765  ```
1766
1767### off('publishSuccess')<sup>9+</sup>
1768
1769off(type: 'publishSuccess', callback?: Callback&lt;{ publishId: number }&gt;): void
1770
1771Unsubscribes from the **'publishSuccess'** event.
1772
1773> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
1774
1775**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1776
1777**System capability**: SystemCapability.DistributedHardware.DeviceManager
1778
1779**Parameters**
1780
1781| Name    | Type                                | Mandatory| Description                         |
1782| -------- | ---------------------------------------- | ---- | --------------------------- |
1783| type     | string                                   | Yes  | Event type. The value **'publishSuccess'** indicates that the information of a device is published |
1784| callback | Callback&lt;{&nbsp;publishId:&nbsp;number&nbsp;}&gt;    | No  | Callback to unregister. |
1785
1786**Example**
1787
1788For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1789  ```ts
1790  import { BusinessError } from '@ohos.base';
1791
1792  class Data {
1793    publishId: number = 0;
1794  }
1795
1796  try {
1797    dmInstance.off('publishSuccess', (data: Data) => {
1798      console.info('publishSuccess' + JSON.stringify(data));
1799    });
1800  } catch (err) {
1801    let e: BusinessError = err as BusinessError;
1802    console.error("publishSuccess errCode:" + e.code + ",errMessage:" + e.message);
1803  }
1804  ```
1805
1806### on('publishFail')<sup>9+</sup>
1807
1808on(type: 'publishFail', callback: Callback&lt;{ publishId: number, reason: number }&gt;): void
1809
1810Subscribes to the **'publishFail'** event. The application will be notified when the information of a device fails to be published.
1811
1812> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
1813
1814**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1815
1816**System capability**: SystemCapability.DistributedHardware.DeviceManager
1817
1818**Parameters**
1819
1820| Name    | Type                                             | Mandatory| Description                            |
1821| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
1822| type     | string                                                | Yes  | Event type. The value **'publishFail'** indicates that the information of a device fails to be published. |
1823| callback | Callback&lt;{&nbsp;publishId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | Yes  | Callback invoked when the information of a device fails to be published. |
1824
1825**Example**
1826
1827For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1828  ```ts
1829  import { BusinessError } from '@ohos.base';
1830
1831  class Data {
1832    publishId: number = 0;
1833    reason: number = 0;
1834  }
1835
1836  try {
1837    dmInstance.on('publishFail', (data: Data) => {
1838      console.info("publishFail on:" + JSON.stringify(data));
1839    });
1840  } catch (err) {
1841    let e: BusinessError = err as BusinessError;
1842    console.error("publishFail errCode:" + e.code + ",errMessage:" + e.message);
1843  }
1844  ```
1845
1846### off('publishFail')<sup>9+</sup>
1847
1848off(type: 'publishFail', callback?: Callback&lt;{ publishId: number, reason: number }&gt;): void
1849
1850Unsubscribes from the **'publishFail'** event.
1851
1852> **NOTE**<br>This API is deprecated since API version 11. There is no substitute API.
1853
1854**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1855
1856**System capability**: SystemCapability.DistributedHardware.DeviceManager
1857
1858**Parameters**
1859
1860| Name    | Type                                             | Mandatory| Description               |
1861| -------- | ----------------------------------------------------- | ---- | ----------------- |
1862| type     | string                                                | Yes  | Event type. The value **'publishFail'** indicates that the information of a device fails to be published. |
1863| callback | Callback&lt;{&nbsp;publishId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | No  | Callback to unregister. |
1864
1865**Example**
1866
1867For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1868  ```ts
1869  import { BusinessError } from '@ohos.base';
1870
1871  class Data {
1872    publishId: number = 0;
1873    reason: number = 0;
1874  }
1875
1876  try {
1877    dmInstance.off('publishFail', (data: Data) => {
1878      console.info('publishFail' + JSON.stringify(data));
1879    });
1880  } catch (err) {
1881    let e: BusinessError = err as BusinessError;
1882    console.error("publishFail errCode:" + e.code + ",errMessage:" + e.message);
1883  }
1884  ```
1885
1886### on('serviceDie')
1887
1888on(type: 'serviceDie', callback: () =&gt; void): void
1889
1890Subscribes to dead events of the **DeviceManager** service. The application will be notified when the **DeviceManager** service is terminated unexpectedly.
1891
1892> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [on('serviceDie')](js-apis-distributedDeviceManager.md#onservicedie).
1893
1894**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1895
1896**System capability**: SystemCapability.DistributedHardware.DeviceManager
1897
1898**Parameters**
1899
1900| Name      | Type                   | Mandatory  | Description                                      |
1901| -------- | ----------------------- | ---- | ---------------------------------------- |
1902| type     | string                  | Yes   | Event type. The value **'serviceDie'** indicates that the **DeviceManager** service is terminated unexpectedly. |
1903| callback | ()&nbsp;=&gt;&nbsp;void | Yes   | Callback invoked when the **DeviceManager** service is terminated unexpectedly. |
1904
1905**Example**
1906
1907For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1908  ```ts
1909  import { BusinessError } from '@ohos.base';
1910
1911  try {
1912    dmInstance.on("serviceDie", () => {
1913      console.info("serviceDie on");
1914    });
1915  } catch (err) {
1916    let e: BusinessError = err as BusinessError;
1917    console.error("serviceDie errCode:" + e.code + ",errMessage:" + e.message);
1918  }
1919  ```
1920
1921### off('serviceDie')
1922
1923off(type: 'serviceDie', callback?: () =&gt; void): void
1924
1925Unsubscribes from dead events of the **DeviceManager** service.
1926
1927> **NOTE**<br>This API is deprecated since API version 11. You are advised to use [off('serviceDie')](js-apis-distributedDeviceManager.md#offservicedie).
1928
1929**Required permissions**: ohos.permission.ACCESS_SERVICE_DM
1930
1931**System capability**: SystemCapability.DistributedHardware.DeviceManager
1932
1933**Parameters**
1934
1935| Name      | Type                   | Mandatory  | Description                                      |
1936| -------- | ----------------------- | ---- | ---------------------------------------- |
1937| type     | string                  | Yes   | Event type. The value **'serviceDie'** indicates that the **DeviceManager** service is terminated unexpectedly. |
1938| callback | ()&nbsp;=&gt;&nbsp;void | No   | Callback to unregister.     |
1939
1940**Example**
1941
1942For details about how to initialize **dmInstance** in the example, see [deviceManager.createDeviceManager](#devicemanagercreatedevicemanager).
1943  ```ts
1944  import { BusinessError } from '@ohos.base';
1945
1946  try {
1947    dmInstance.off("serviceDie", () => {
1948      console.info("serviceDie off");
1949    });
1950  } catch (err) {
1951    let e: BusinessError = err as BusinessError;
1952    console.error("serviceDie errCode:" + e.code + ",errMessage:" + e.message);
1953  }
1954  ```
1955