diff --git a/en/application-dev/reference/apis/js-apis-device-manager.md b/en/application-dev/reference/apis/js-apis-device-manager.md index 43e248fb82075971c2e32b7fa77003d9ddff5bf3..93ab553ef10e531fea0b2d0871b65183d22bf6fa 100644 --- a/en/application-dev/reference/apis/js-apis-device-manager.md +++ b/en/application-dev/reference/apis/js-apis-device-manager.md @@ -1,456 +1,213 @@ -# Device Management +# Device Management ->![](../../public_sys-resources/icon-note.gif) **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. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **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'; ``` -## deviceManager.createDeviceManager - -createDeviceManager\(bundleName: string, callback: AsyncCallback\): void - -Creates a **DeviceManager** instance. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

bundleName

-

string

-

Yes

-

Bundle name of the application.

-

callback

-

AsyncCallback<DeviceManager>

-

Yes

-

Callback invoked to return the DeviceManager instance created.

-
- -- Example - - ``` - deviceManager.createDeviceManager("ohos.samples.jshelloworld", (err, data) => { - if (err) { - console.info("createDeviceManager err:" + JSON.stringify(err)); - return; - } - console.info("createDeviceManager success"); - this.dmInstance = data; - }); - ``` - - -## DeviceStateChangeAction + +## deviceManager.createDeviceManager + +createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void + +Creates a **DeviceManager** instance. + +**System capability**: SystemCapability.DistributedHardware.DeviceManager + +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | bundleName | string | Yes| Bundle name of the application.| + | callback | AsyncCallback<[DeviceManager](#devicemanager)> | Yes| Callback invoked to return the **DeviceManager** instance created.| + +- Example + ``` + deviceManager.createDeviceManager("ohos.samples.jshelloworld", (err, data) => { + if (err) { + console.info("createDeviceManager err:" + JSON.stringify(err)); + return; + } + console.info("createDeviceManager success"); + this.dmInstance = data; + }); + ``` + + +## DeviceStateChangeAction Enumerates the device states. - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

ONLINE

-

0

-

The device is online.

-

READY

-

1

-

The device is ready, and the device information has been synchronized.

-

OFFLINE

-

2

-

The device is offline.

-

CHANGE

-

3

-

The device information is changed.

-
- -## DeviceType - -Enumerates device types. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

SPEAKER

-

0x0A

-

Smart speaker.

-

PHONE

-

0x0E

-

Phone.

-

TABLET

-

0x11

-

Tablet.

-

WEARABLE

-

0x6D

-

Wearable.

-

TV

-

0x9C

-

Smart TV.

-
- -## DeviceInfo +**System capability**: SystemCapability.DistributedHardware.DeviceManager + +| Name| Default Value| Description| +| -------- | -------- | -------- | +| ONLINE | 0 | The device is online.| +| READY | 1 | The device is ready, and the device information has been synchronized.| +| OFFLINE | 2 | The device is offline.| +| CHANGE | 3 | The device information is changed.| + + +## DeviceType + +Enumerates the device types. + +**System capability**: SystemCapability.DistributedHardware.DeviceManager + +| Name| Default Value| Description| +| -------- | -------- | -------- | +| SPEAKER | 0x0A | Smart speaker.| +| PHONE | 0x0E | Phone.| +| TABLET | 0x11 | Tablet.| +| WEARABLE | 0x6D | Wearable.| +| TV | 0x9C | Smart TV.| +| CAR | 0x83 | Car.| +| UNKNOWN_TYPE | 0 | Unknown device type.| + + +## DeviceInfo Defines device information. - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

deviceId

-

number

-

Yes

-

Unique device identifier.

-

deviceName

-

string

-

Yes

-

Device name.

-

deviceType

-

number

-

Yes

-

Device type.

-
- -## DeviceManager - -Creates a **DeviceManager** instance to obtain information about trusted devices and local devices. Before calling any method in **DeviceManager**, you must use **createDeviceManager** to create a **DeviceManager** instance, for example, **dmInstance**. - -### release - -release\(\): void - -Releases the **DeviceManager** instance that is no longer used. - -- Example - - ``` - dmInstance.release(); - ``` - - -### getTrustedDeviceListSync - -getTrustedDeviceListSync\(\): Array +**System capability**: SystemCapability.DistributedHardware.DeviceManager -Obtains all trusted devices synchronously. +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| deviceId | number | Yes| Unique device identifier.| +| deviceName | string | Yes| Device name.| +| deviceType | number | Yes| Device type.| + + +## DeviceManager -- Return values +Provides 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**. - - - - - - - - - -

Name

-

Description

-

Array<DeviceInfo>

-

List of trusted devices obtained.

-
-- Example +### release - ``` - var deviceInfoList = dmInstance.getTrustedDeviceListSync(); - ``` +release(): void +Releases the **DeviceManager** instance that is no longer used. -### on\('deviceStateChange'\) +**System capability**: SystemCapability.DistributedHardware.DeviceManager + +- Example + ``` + dmInstance.release(); + ``` + + +### getTrustedDeviceListSync + +getTrustedDeviceListSync(): Array<DeviceInfo> + +Obtains all trusted devices synchronously. -on\(type: 'deviceStateChange', callback: Callback<\{ action: DeviceStateChangeAction, device: DeviceInfo \}\>\): void +**System capability**: SystemCapability.DistributedHardware.DeviceManager + +- Return value + | Name| Description| + | -------- | -------- | + | Array<[DeviceInfo](#deviceinfo)> | List of trusted devices obtained.| + +- Example + ``` + var deviceInfoList = dmInstance.getTrustedDeviceListSync(); + ``` + + +### on('deviceStateChange') + +on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void Subscribes to changes in the device state. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

string

-

Yes

-

Event type. The value is deviceStateChange, which indicates a device state change event.

-

callback

-

Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>

-

Yes

-

Callback invoked to return the device information and state.

-
- - -- Example - - ``` - dmInstance.on('deviceStateChange', (data) => { - console.info("deviceStateChange on:" + JSON.stringify(data)); - } - ); - ``` - - -### off\('deviceStateChange'\) - -off\(type: 'deviceStateChange', callback?: Call back<\{ action: DeviceStateChangeAction, device: DeviceInfo \}\>\): void +**System capability**: SystemCapability.DistributedHardware.DeviceManager -Unsubscribes from changes in the device state. +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | 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.| -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

string

-

Yes

-

Event type. The value deviceStateChange indicates an event of device state change.

-

callback

-

Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>

-

Yes

-

Callback used to return the device state changes.

-
- - -- Example - - ``` - dmInstance.off('deviceStateChange', (data) => { - console.info('deviceStateChange' + JSON.stringify(data)); - } - ); - ``` - - -### on\('serviceDie'\) - -on\(type: 'serviceDie', callback: \(\) =\> void\): void - -Subscribes to dead events of the **DeviceManager** service. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

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 - - ``` - dmInstance.on("serviceDie", () => { - console.info("serviceDie on"); - } - ); - ``` - - -### off\('serviceDie'\) - -off\(type: 'serviceDie', callback?: \(\) =\> void\): void - -Unsubscribes from dead events of the **DeviceManager** service. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

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.

-
- - -- Example - - ``` - dmInstance.off("serviceDie", () => { - console.info("serviceDie off"); +- Example + ``` + dmInstance.on('deviceStateChange', (data) => { + console.info("deviceStateChange on:" + JSON.stringify(data)); } - ); - ``` + ); + ``` + + +### off('deviceStateChange') + +off(type: 'deviceStateChange', callback?: Call back<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void + +Unsubscribes from changes in the device state. + +**System capability**: SystemCapability.DistributedHardware.DeviceManager + +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | 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.| + +- Example + ``` + dmInstance.off('deviceStateChange', (data) => { + console.info('deviceStateChange' + JSON.stringify(data)); + } + ); + ``` + + +### on('serviceDie') + +on(type: 'serviceDie', callback: () => void): void + +Subscribes to dead events of the **DeviceManager** service. + +**System capability**: SystemCapability.DistributedHardware.DeviceManager + +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | 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 + ``` + dmInstance.on("serviceDie", () => { + console.info("serviceDie on"); + } + ); + ``` + + +### off('serviceDie') + +off(type: 'serviceDie', callback?: () => void): void + +Unsubscribes from dead events of the **DeviceManager** service. + +**System capability**: SystemCapability.DistributedHardware.DeviceManager +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | 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.| +- Example + ``` + dmInstance.off("serviceDie", () => { + console.info("serviceDie off"); + } + ); + ```