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