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