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

!13568 翻译完成:12400+12440

Merge pull request !13568 from wusongqing/TR12400
...@@ -3,30 +3,18 @@ ...@@ -3,30 +3,18 @@
## When to Use ## When to Use
- Data provided by the compass sensor denotes the current orientation of the user device, which helps your application accurately navigate for the user. With the sensor module, a device can obtain sensor data. For example, the device can subscribe to data of the orientation sensor to detect its own orientation, and data of the pedometer sensor to learn the number of steps the user walks every day.
- Data provided by the proximity sensor denotes the distance between the device and a visible object, which enables the device to automatically turn on or off its screen accordingly to prevent accidental touch on the screen. For details about the APIs, see [Sensor](../reference/apis/js-apis-sensor.md).
- Data provided by the barometer sensor helps your application accurately determine the altitude of the device.
- Data provided by the ambient light sensor helps your device automatically adjust its backlight.
- Data provided by the Hall effect sensor implements the smart cover mode of your device.
- Data provided by the heart rate sensor helps your application track the heart health of a user.
- Data provided by the pedometer sensor helps your application obtain the number of steps a user has walked.
- Data provided by the wear detection sensor helps your application detect whether a user is wearing a wearable device.
## Available APIs ## Available APIs
| Module| API| Description| | Module| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.sensor | sensor.on(sensorType, callback:AsyncCallback<Response>): void | Subscribes to data changes of a type of sensor.| | ohos.sensor | sensor.on(sensorId, callback:AsyncCallback<Response>): void | Subscribes to data changes of a type of sensor.|
| ohos.sensor | sensor.once(sensorType, callback:AsyncCallback<Response>): void | Subscribes to only one data change of a type of sensor.| | ohos.sensor | sensor.once(sensorId, callback:AsyncCallback<Response>): void | Subscribes to only one data change of a type of sensor.|
| ohos.sensor | sensor.off(sensorType, callback?:AsyncCallback<void>): void | Unsubscribes from sensor data changes.| | ohos.sensor | sensor.off(sensorId, callback?:AsyncCallback<void>): void | Unsubscribes from sensor data changes.|
## How to Develop ## How to Develop
...@@ -43,52 +31,49 @@ ...@@ -43,52 +31,49 @@
For details about how to configure a permission, see [Declaring Permissions](../security/accesstoken-guidelines.md). For details about how to configure a permission, see [Declaring Permissions](../security/accesstoken-guidelines.md).
2. Subscribe to data changes of a type of sensor. 2. Subscribe to data changes of a type of sensor. The following uses the acceleration sensor as an example.
``` ```js
import sensor from "@ohos.sensor"; import sensor from "@ohos.sensor";
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(data){ sensor.on(sensor.SensorId.ACCELEROMETER, function(data){
console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z);// Data is obtained.
}); });
``` ```
The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**.
![en-us_image_0000001241693881](figures/en-us_image_0000001241693881.png) ![171e6f30-a8d9-414c-bafa-b430340305fb](figures/171e6f30-a8d9-414c-bafa-b430340305fb.png)
3. Unsubscribe from sensor data changes. 3. Unsubscribe from sensor data changes.
``` ```js
import sensor from "@ohos.sensor"; import sensor from "@ohos.sensor";
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER); sensor.off(sensor.SensorId.ACCELEROMETER);
``` ```
The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**.
![en-us_image_0000001196654004](figures/en-us_image_0000001196654004.png) ![65d69983-29f6-4381-80a3-f9ef2ec19e53](figures/65d69983-29f6-4381-80a3-f9ef2ec19e53.png)
4. Subscribe to only one data change of a type of sensor. 4. Subscribe to only one data change of a type of sensor.
``` ```js
import sensor from "@ohos.sensor"; import sensor from "@ohos.sensor";
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(data) { sensor.once(sensor.SensorId.ACCELEROMETER, function(data) {
console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z);// Data is obtained.
}); });
``` ```
The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**.
![en-us_image_0000001241733907](figures/en-us_image_0000001241733907.png) ![db5d017d-6c1c-4a71-a2dd-f74b7f23239e](figures/db5d017d-6c1c-4a71-a2dd-f74b7f23239e.png)
If the API fails to be called, you are advised to use the **try/catch** statement to capture error information that may occur in the code. Example: If the API fails to be called, you are advised to use the **try/catch** statement to capture error information that may occur in the code. Example:
``` ```js
import sensor from "@ohos.sensor"; import sensor from "@ohos.sensor";
try { try {
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(data) { sensor.once(sensor.SensorId.ACCELEROMETER, function(data) {
console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z);// Data is obtained.
}); });
} catch (error) { } catch (error) {
console.error("Failed to get sensor data"); console.error("Get sensor data error. data:" + error.data, " msg:", error.message);
} }
``` ```
\ No newline at end of file
...@@ -34,8 +34,7 @@ For details about the APIs, see [AudioRenderer in Audio Management](../reference ...@@ -34,8 +34,7 @@ For details about the APIs, see [AudioRenderer in Audio Management](../reference
1. Use **createAudioRenderer()** to create an **AudioRenderer** instance. 1. Use **createAudioRenderer()** to create an **AudioRenderer** instance.
Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. This instance is used to render audio, control and obtain the rendering status, and register a callback for notification.
Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. This instance is used to render audio, control and obtain the rendering status, and register a callback for notification.
```js ```js
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
**Error Message** **Error Message**
Session service exception Session service exception.
**Description** **Description**
...@@ -24,7 +24,7 @@ The session service is killed during session restart. ...@@ -24,7 +24,7 @@ The session service is killed during session restart.
**Error Message** **Error Message**
The session does not exist The session does not exist.
**Description** **Description**
...@@ -44,7 +44,7 @@ The session has been destroyed, and no session record exists on the server. ...@@ -44,7 +44,7 @@ The session has been destroyed, and no session record exists on the server.
**Error Message** **Error Message**
The session controller does not exist The session controller does not exist.
**Description** **Description**
...@@ -62,7 +62,7 @@ Query the session record and create the corresponding controller. ...@@ -62,7 +62,7 @@ Query the session record and create the corresponding controller.
**Error Message** **Error Message**
The remote session connection failed The remote session connection failed.
**Description** **Description**
...@@ -80,7 +80,7 @@ Stop sending control commands to the session. Subscribe to output device changes ...@@ -80,7 +80,7 @@ Stop sending control commands to the session. Subscribe to output device changes
**Error Message** **Error Message**
Invalid session command Invalid session command.
**Description** **Description**
...@@ -98,7 +98,7 @@ Stop sending the command or event. Query the commands supported by the session, ...@@ -98,7 +98,7 @@ Stop sending the command or event. Query the commands supported by the session,
**Error Message** **Error Message**
The session not active The session is not activated.
**Description** **Description**
...@@ -116,7 +116,7 @@ Stop sending the command or event. Subscribe to the session activation status, a ...@@ -116,7 +116,7 @@ Stop sending the command or event. Subscribe to the session activation status, a
**Error Message** **Error Message**
Command or event overload Too many commands or events.
**Description** **Description**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册