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 5d6b71b99b23044250b231f34630a973f0705515..16ec1aec98084c7e3551e4a77406930b17cde50f 100644 --- a/en/application-dev/reference/apis/js-apis-device-manager.md +++ b/en/application-dev/reference/apis/js-apis-device-manager.md @@ -73,12 +73,12 @@ Defines device information. | Name | Type | Mandatory | Description | | ---------------------- | ------------------------- | ---- | -------- | -| deviceId | string | Yes | Unique identifier of a device.| +| deviceId | string | Yes | Unique identifier of the device.| | deviceName | string | Yes | Device name. | | deviceType | [DeviceType](#devicetype) | Yes | Device type. | | networkId8+ | string | Yes | Network ID of the device. | | range9+ | number | Yes | Distance between the device (discovered device) and the device that initiates device discovery. | -| authForm10+ | [AuthForm](#authform) | Yes | Authentication type of the device. | +| authForm10+ | [AuthForm](#authform10) | Yes | Authentication type of the device. | ## DeviceType @@ -199,7 +199,7 @@ Defines the authentication parameters. | Name | Type | Mandatory | Description | | --------- | -------------------- | ---- | ---------- | | authType | number | Yes | Authentication type. | -| extraInfo | {[key:string] : any} | No | Extended field.| +| extraInfo | {[key:string] : any} | No | Extended field.| ## AuthInfo @@ -211,7 +211,7 @@ Defines authentication information. | --------- | -------------------- | ---- | ---------- | | authType | number | Yes | Authentication type. | | token | number | Yes | Authentication token. | -| extraInfo | {[key:string] : any} | No | Extended field.| +| extraInfo | {[key:string] : any} | No | Extended field.| ## PublishInfo9+ @@ -460,6 +460,83 @@ For details about the error codes, see [Device Management Error Codes](../errorc }); ``` +### getDeviceInfo10+ + +getDeviceInfo(networkId: string, callback:AsyncCallback<DeviceInfo>): void + +Obtains the information about a specific device based on the network ID. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.DistributedHardware.DeviceManager + +**Parameters** + + | Name | Type | Mandatory | Description | + | -------- | ---------------------------------------- | ---- | --------- | + | networkId| string | Yes | Network ID of the device.| + | callback | AsyncCallback<[DeviceInfo](#deviceinfo)> | Yes | Callback used to return the information about the specified device.| + +**Error codes** + +For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md). + +| ID| Error Message | +| -------- | --------------------------------------------------------------- | +| 11600101 | Failed to execute the function. | + +**Example** + + ```js + try { + dmInstance.getDeviceInfo(networkId, (err, data) => { + if (err) { + console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message); + return; + } + console.log('get device info: ' + JSON.stringify(data)); + }); + } catch (err) { + console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message); + } + ``` + +### getDeviceInfo10+ + +getDeviceInfo(networkId: string): Promise<DeviceInfo> + +Obtains the information about a specific device based on the network ID. This API uses a promise to return the result. + +**System capability**: SystemCapability.DistributedHardware.DeviceManager + +**Parameters** + + | Name | Type | Mandatory| Description | + | -------- | ---------------------------------------- | ---- | --------- | + | networkId| string | Yes | Network ID of the device.| + +**Return value** + + | Type | Description | + | ---------------------------------------- | --------------------- | + | Promise<[DeviceInfo](#deviceinfo)> | Promise used to return the result.| + +**Error codes** + +For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md). + +| ID| Error Message | +| ------- | --------------------------------------------------------------- | +| 11600101| Failed to execute the function. | + +**Example** + + ```js + dmInstance.getDeviceInfo(networkId).then((data) => { + console.log('get device info: ' + JSON.stringify(data)); + }).catch((err) => { + console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message); + }); + ``` + ### startDeviceDiscovery8+ startDeviceDiscovery(subscribeInfo: SubscribeInfo): void @@ -491,8 +568,8 @@ For details about the error codes, see [Device Management Error Codes](../errorc var subscribeInfo = { "subscribeId": subscribeId, "mode": 0xAA, // Active discovery - "medium": 0, // Automatic. Multiple media can be used for device discovery. - "freq": 2, // High frequency + "medium": 0, // Automatic. Multiple media can be used for device discovery. + "freq": 2, // High frequency "isSameAccount": false, "isWakeRemote": false, "capability": 1 @@ -536,8 +613,8 @@ For details about the error codes, see [Device Management Error Codes](../errorc var subscribeInfo = { "subscribeId": subscribeId, "mode": 0xAA, // Active discovery - "medium": 0, // Automatic. Multiple media can be used for device discovery. - "freq": 2, // High frequency + "medium": 0, // Automatic. Multiple media can be used for device discovery. + "freq": 2, // High frequency "isSameAccount": false, "isWakeRemote": false, "capability": 1 @@ -604,7 +681,7 @@ Publishes device information for discovery purposes. | Name | Type | Mandatory| Description | | ------------- | ------------------------------- | ---- | ----- | - | publishInfo | [PublishInfo](#publishinfo) | Yes | Device information to publish.| + | publishInfo | [PublishInfo](#publishinfo9) | Yes | Device information to publish.| **Error codes** @@ -623,7 +700,7 @@ For details about the error codes, see [Device Management Error Codes](../errorc var publishInfo = { "publishId": publishId, "mode": 0xAA, // Active discovery - "freq": 2, // High frequency + "freq": 2, // High frequency "ranging": true // The device supports reporting the distance to the discovery initiator. }; try { @@ -681,7 +758,7 @@ Authenticates a device. | ---------- | ---------------------------------------- | ---- | ------- | | deviceInfo | [DeviceInfo](#deviceinfo) | Yes | Device information. | | authParam | [AuthParam](#authparam) | Yes | Authentication parameter. | - | callback | AsyncCallback<{deviceId: string, pinToken ?: number}> | Yes | Callback used to return the authentication result.| + | callback | AsyncCallback<{deviceId: string, pinToken ?: number}> | Yes | Callback used to return the authentication result.| **Error codes** @@ -779,7 +856,7 @@ Verifies authentication information. | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------- | | authInfo | [AuthInfo](#authinfo) | Yes | Authentication information. | - | callback | AsyncCallback<{deviceId: string, level: number}> | Yes | Callback used to return the verification result.| + | callback | AsyncCallback<{deviceId: string, level: number}> | Yes | Callback used to return the verification result.| **Error codes** @@ -979,7 +1056,7 @@ Subscribes to UI status changes. | Name | Type | Mandatory| Description | | -------- | ------------------------------------ | ---- | ------------------------------ | | type | string | Yes | Event type. The value **'uiStateChange'** indicates a UI status change event.| - | callback | Callback<{ param: string}> | Yes | Callback used to return the UI status. | + | callback | Callback<{ param: string}> | Yes | Callback used to return the UI status. | **Example** @@ -1009,7 +1086,7 @@ Unsubscribes from UI status changes. | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | ------------------------------ | | type | string | Yes | Event type. The value **'uiStateChange'** indicates a UI status change event.| - | callback | Callback<{ param: string}> | No | Callback used to return the UI status.| + | callback | Callback<{ param: string}> | No | Callback used to return the UI status.| **Example** @@ -1088,7 +1165,7 @@ Subscribes to device discovery events. | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | -------------------------- | | 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. | + | callback | Callback<{ subscribeId: number, device: [DeviceInfo](#deviceinfo) }> | Yes | Callback used for device discovery. | **Example** @@ -1115,7 +1192,7 @@ Unsubscribes from device discovery events. | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | --------------------------- | | type | string | Yes | Event type. The value **'deviceFound'** indicates an event reported when a device is discovered. | - | callback | Callback<{ subscribeId: number, device: [DeviceInfo](#deviceinfo) }> | No | Callback used to return the device information and state.| + | callback | Callback<{ subscribeId: number, device: [DeviceInfo](#deviceinfo) }> | No | Callback used to return the device information and state.| **Example** @@ -1142,7 +1219,7 @@ Subscribes to device discovery failures. | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------------------ | | type | string | Yes | Event type. The event **'discoverFail'** indicates an event reported when device discovery fails.| - | callback | Callback<{ subscribeId: number, reason: number }> | Yes | Callback used for the device discovery failure. | + | callback | Callback<{ subscribeId: number, reason: number }> | Yes | Callback used for the device discovery failure. | **Example** @@ -1169,7 +1246,7 @@ Unsubscribes from device discovery failures. | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ----------------- | | type | string | Yes | Event type. The event **'discoverFail'** indicates an event reported when device discovery fails. | - | callback | Callback<{ subscribeId: number, reason: number }> | No | Callback used for the device discovery failure.| + | callback | Callback<{ subscribeId: number, reason: number }> | No | Callback used for the device discovery failure.| **Example** @@ -1196,7 +1273,7 @@ Subscribes to device information publication success events. | Name | Type | Mandatory| Description | | -------- | ---------------------------------------- | ---- | -------------------------- | | type | string | Yes | Event type. The value **'publishSuccess'** indicates an event reported when device information is published.| - | callback | Callback<{ publishId: number }> | Yes | Callback used to return the publish ID. | + | callback | Callback<{ publishId: number }> | Yes | Callback used to return the publish ID. | **Example** @@ -1224,7 +1301,7 @@ Unsubscribes from device information publication success events. | Name | Type | Mandatory| Description | | -------- | ---------------------------------------- | ---- | --------------------------- | | type | string | Yes | Event type. The value **'publishSuccess'** indicates an event reported when device information is published. | - | callback | Callback<{ publishId: number }> | No | Callback used to return the publish ID.| + | callback | Callback<{ publishId: number }> | No | Callback used to return the publish ID.| **Example** @@ -1251,7 +1328,7 @@ Subscribes to device information publication failures. | Name | Type | Mandatory| Description | | -------- | ----------------------------------------------------- | ---- | ------------------------------ | | type | string | Yes | Event type. The event **'publishFail'** indicates an event reported when publishing device information fails.| - | callback | Callback<{ publishId: number, reason: number }> | Yes | Callback used for the publication failure. | + | callback | Callback<{ publishId: number, reason: number }> | Yes | Callback used for the publication failure. | **Example** @@ -1278,7 +1355,7 @@ Unsubscribes from device information publication failures. | Name | Type | Mandatory| Description | | -------- | ----------------------------------------------------- | ---- | ----------------- | | type | string | Yes | Event type. The event **'publishFail'** indicates an event reported when publishing device information fails. | - | callback | Callback<{ publishId: number, reason: number }> | No | Callback used for the device discovery failure.| + | callback | Callback<{ publishId: number, reason: number }> | No | Callback used for the device discovery failure.| **Example** @@ -1305,7 +1382,7 @@ Subscribes to dead events of the **DeviceManager** service. | 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. | + | callback | () => void | Yes | Callback invoked when a dead event of the **DeviceManager** service occurs. | **Example** @@ -1332,7 +1409,7 @@ Unsubscribes from dead events of the **DeviceManager** service. | 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. | + | callback | () => void | No | Callback used to return the dead event of the **DeviceManager** service. | **Example**