未验证 提交 f72e3916 编写于 作者: O openharmony_ci 提交者: Gitee

!17731 翻译完成 16816:获取指定设备信息

Merge pull request !17731 from ester.zhou/TR-16246
......@@ -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. |
| networkId<sup>8+</sup> | string | Yes | Network ID of the device. |
| range<sup>9+</sup> | number | Yes | Distance between the device (discovered device) and the device that initiates device discovery. |
| authForm<sup>10+</sup> | [AuthForm](#authform) | Yes | Authentication type of the device. |
| authForm<sup>10+</sup> | [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]&nbsp;:&nbsp;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]&nbsp;:&nbsp;any} | No | Extended field.|
| extraInfo | {[key:string] : any} | No | Extended field.|
## PublishInfo<sup>9+</sup>
......@@ -460,6 +460,83 @@ For details about the error codes, see [Device Management Error Codes](../errorc
});
```
### getDeviceInfo<sup>10+</sup>
getDeviceInfo(networkId: string, callback:AsyncCallback&lt;DeviceInfo&gt;): 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&lt;[DeviceInfo](#deviceinfo)&gt; | 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);
}
```
### getDeviceInfo<sup>10+</sup>
getDeviceInfo(networkId: string): Promise&lt;DeviceInfo&gt;
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&lt;[DeviceInfo](#deviceinfo)&gt; | 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);
});
```
### startDeviceDiscovery<sup>8+</sup>
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&lt;{deviceId:&nbsp;string,&nbsp;pinToken&nbsp;?:&nbsp;number}&gt; | Yes | Callback used to return the authentication result.|
| callback | AsyncCallback&lt;{deviceId: string, pinToken ?: number}&gt; | 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&lt;{deviceId:&nbsp;string,&nbsp;level:&nbsp;number}&gt; | Yes | Callback used to return the verification result.|
| callback | AsyncCallback&lt;{deviceId: string, level: number}&gt; | 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&lt;{&nbsp;param:&nbsp;string}&gt; | Yes | Callback used to return the UI status. |
| callback | Callback&lt;{ param: string}&gt; | 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&lt;{&nbsp;param:&nbsp;string}&gt; | No | Callback used to return the UI status.|
| callback | Callback&lt;{ param: string}&gt; | 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&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | Yes | Callback used for device discovery. |
| callback | Callback&lt;{ subscribeId: number, device: [DeviceInfo](#deviceinfo) }&gt; | 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&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | No | Callback used to return the device information and state.|
| callback | Callback&lt;{ subscribeId: number, device: [DeviceInfo](#deviceinfo) }&gt; | 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&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | Yes | Callback used for the device discovery failure. |
| callback | Callback&lt;{ subscribeId: number, reason: number }&gt; | 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&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | No | Callback used for the device discovery failure.|
| callback | Callback&lt;{ subscribeId: number, reason: number }&gt; | 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&lt;{&nbsp;publishId:&nbsp;number&nbsp;}&gt; | Yes | Callback used to return the publish ID. |
| callback | Callback&lt;{ publishId: number }&gt; | 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&lt;{&nbsp;publishId:&nbsp;number&nbsp;}&gt; | No | Callback used to return the publish ID.|
| callback | Callback&lt;{ publishId: number }&gt; | 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&lt;{&nbsp;publishId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | Yes | Callback used for the publication failure. |
| callback | Callback&lt;{ publishId: number, reason: number }&gt; | 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&lt;{&nbsp;publishId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | No | Callback used for the device discovery failure.|
| callback | Callback&lt;{ publishId: number, reason: number }&gt; | 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 | ()&nbsp;=&gt;&nbsp;void | Yes | Callback invoked when a dead event of the **DeviceManager** service occurs. |
| callback | () =&gt; 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 | ()&nbsp;=&gt;&nbsp;void | No | Callback used to return the dead event of the **DeviceManager** service. |
| callback | () =&gt; void | No | Callback used to return the dead event of the **DeviceManager** service. |
**Example**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册