The **DeviceManager** module provides APIs for distributed device management.
System applications can call the APIs to do the following:
- Subscribe to or unsubscribe from device state changes.
- Discover peripheral untrusted devices.
- Authenticate or deauthenticate a device.
- Query the trusted device list.
- Query local device information, including the device name, type, and ID.
> **NOTE**
>
> - 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.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
## Modules to import:
## Modules to Import
```
import deviceManager from '@ohos.distributedHardware.deviceManager';
...
...
@@ -21,10 +32,10 @@ Creates a **DeviceManager** instance.
| type | string | Yes| Event type. The value is **deviceStateChange**, which indicates a device state change event.|
| callback | Callback<{ action: [DeviceStateChangeAction](#devicestatechangeaction), device: [DeviceInfo](#deviceinfo) }> | Yes| Callback invoked to return the device information and state.|
| type | string | Yes| Event type. The value **deviceStateChange** indicates an event of device state change.|
| callback | Callback<{ action: [DeviceStateChangeAction](#devicestatechangeaction), device: [DeviceInfo](#deviceinfo) }> | Yes| Callback invoked to return the device information and state.|
| type | string | Yes | Event type. The value **'deviceFound'** indicates an event reported when a device is discovered. |
| callback | Callback<{ subscribeId: number, device: [DeviceInfo](#deviceinfo) }> | Yes | Callback used for device discovery, which is invoked to return the device information and state.|
- Example
```js
dmInstance.off('deviceFound',(data)=>{
console.info('deviceFound'+JSON.stringify(data));
}
);
```
### on('discoverFail')
on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: number }>): void
| type | string | Yes| Event type. The value **serviceDie** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.|
| callback | () => void | Yes| Callback invoked when a dead event of the **DeviceManager** service occurs.|
| type | string | Yes | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.|
| callback | () => void | Yes | Callback invoked when a dead event of the **DeviceManager** service occurs. |
- Example
```
```js
dmInstance.on("serviceDie",()=>{
console.info("serviceDie on");
}
...
...
@@ -199,13 +632,13 @@ Unsubscribes from dead events of the **DeviceManager** service.
| type | string | Yes| Event type. The value **serviceDie** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.|
| callback | () => void | No| Callback used to return the dead event of the **DeviceManager** service.|
| type | string | Yes | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.|
| callback | () => void | No | Callback used to return the dead event of the **DeviceManager** service. |