From 311ba1b4a7de84c9db7c213918bab76f2cbaebd9 Mon Sep 17 00:00:00 2001 From: wusongqing Date: Fri, 18 Mar 2022 11:56:09 +0800 Subject: [PATCH] updated sensor and vibrator APIs Signed-off-by: wusongqing --- .../reference/apis/js-apis-sensor.md | 1643 +++++++++++------ .../reference/apis/js-apis-vibrator.md | 47 +- 2 files changed, 1146 insertions(+), 544 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-sensor.md b/en/application-dev/reference/apis/js-apis-sensor.md index 8b9cf97f18..b163b58eb4 100644 --- a/en/application-dev/reference/apis/js-apis-sensor.md +++ b/en/application-dev/reference/apis/js-apis-sensor.md @@ -10,43 +10,28 @@ import sensor from '@ohos.sensor'; ``` -## System Capabilities -SystemCapability.Sensors.Sensor +## sensor.on(SensorType.SENSOR_TYPE_ID_ACCELEROMETER) -## Required Permissions +on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<AccelerometerResponse>,options?: Options): void -To use the pedometer sensor, you must declare the **ohos.permission.ACTIVITY_MOTION** permission. - -To use the heart rate sensor, you must declare the **ohos.permission.READ_HEALTH_DATA** permission. - -To use the acceleration sensor, you must declare the **ohos.permission.ACCELEROMETER** permission. - -To use the gyroscope sensor, you must declare the **ohos.permission.GYROSCOPE** permission. - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallback<AccelerometerResponse>,options?: Options): void +Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. +**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) -Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.| - | callback | AsyncCallback<[AccelerometerResponse](#accelerometerresponse)> | Yes| Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.| + | callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes| Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){ console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -56,26 +41,26 @@ Subscribes to data changes of the acceleration sensor. If this API is called mul ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION) +## sensor.on(SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION) -on(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallback<LinearAccelerometerResponse>, options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<LinearAccelerometerResponse>, options?: Options): void Subscribes to data changes of the linear acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. +**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.| - | callback | AsyncCallback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes| Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.| + | callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes| Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,function(data){ console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -85,26 +70,26 @@ Subscribes to data changes of the linear acceleration sensor. If this API is cal ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED) +## sensor.on(SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED) -on(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:AsyncCallback<AccelerometerUncalibratedResponse>, options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback<AccelerometerUncalibratedResponse>, options?: Options): void Subscribes to data changes of the uncalibrated acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. +**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.| - | callback | AsyncCallback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes| Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.| + | callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes| Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){ console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -117,26 +102,24 @@ Subscribes to data changes of the uncalibrated acceleration sensor. If this API ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY) +## sensor.on(SensorType.SENSOR_TYPE_ID_GRAVITY) -on(type: sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<GravityResponse>,options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityResponse>,options?: Options): void Subscribes to data changes of the gravity sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.| - | callback | AsyncCallback<[GravityResponse](#gravityresponse)> | Yes| Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.| + | callback | Callback<[GravityResponse](#gravityresponse)> | Yes| Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){ console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -146,26 +129,26 @@ Subscribes to data changes of the gravity sensor. If this API is called multiple ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE) +## sensor.on(SensorType.SENSOR_TYPE_ID_GYROSCOPE) -on(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback<GyroscopeResponse>, options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeResponse>, options?: Options): void Subscribes to data changes of the gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect. +**Required permissions**: ohos.permission.GYROSCOPE (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.| - | callback | AsyncCallback<[GyroscopeResponse](#gyroscoperesponse)> | Yes| Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.| + | callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes| Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){ console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -175,26 +158,26 @@ Subscribes to data changes of the gyroscope sensor. If this API is called multip ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED) +## sensor.on(SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED) -on(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCallback<GyroscopeUncalibratedResponse>, options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback<GyroscopeUncalibratedResponse>, options?: Options): void Subscribes to data changes of the uncalibrated gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect. +**Required permissions**: ohos.permission.GYROSCOPE (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.| - | callback | AsyncCallback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes| Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.| + | callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes| Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){ console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -207,26 +190,24 @@ Subscribes to data changes of the uncalibrated gyroscope sensor. If this API is ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION) +## sensor.on(SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION) -on(type: sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: AsyncCallback<SignificantMotionResponse>, options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback<SignificantMotionResponse>, options?: Options): void Subscribes to data changes of the significant motion sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.| - | callback | AsyncCallback<[SignificantMotionResponse](#significantmotionresponse)> | Yes| Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.| + | callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes| Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){ console.info('Scalar data: ' + data.scalar); }, {interval: 10000000} @@ -234,26 +215,26 @@ Subscribes to data changes of the significant motion sensor. If this API is call ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION) +## sensor.on(SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION) -on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: AsyncCallback<PedometerDetectResponse>, options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback<PedometerDetectionResponse>, options?: Options): void Subscribes to data changes of the pedometer detection sensor. If this API is called multiple times for the same application, the last call takes effect. +**Required permissions**: ohos.permission.ACTIVITY_MOTION + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.| - | callback | AsyncCallback<[PedometerDetectResponse](#pedometerdetectresponse)> | Yes| Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectResponse**.| + | callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes| Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){ console.info('Scalar data: ' + data.scalar); }, {interval: 10000000} @@ -261,26 +242,26 @@ Subscribes to data changes of the pedometer detection sensor. If this API is cal ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER) +## sensor.on(SensorType.SENSOR_TYPE_ID_PEDOMETER) -on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback<PedometerResponse>, options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerResponse>, options?: Options): void Subscribes to data changes of the pedometer sensor. If this API is called multiple times for the same application, the last call takes effect. +**Required permissions**: ohos.permission.ACTIVITY_MOTION + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.| - | callback | AsyncCallback<[PedometerResponse](#pedometerresponse)> | Yes| Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.| + | callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes| Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){ console.info('Steps: ' + data.steps); }, {interval: 10000000} @@ -288,26 +269,24 @@ Subscribes to data changes of the pedometer sensor. If this API is called multip ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE) +## sensor.on(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE) -on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallback<AmbientTemperatureResponse>, options?: Options): void +on(type:SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback<AmbientTemperatureResponse>, options?: Options): void Subscribes to data changes of the ambient temperature sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.| - | callback | AsyncCallback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes| Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.| + | callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes| Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){ console.info('Temperature: ' + data.temperature); }, {interval: 10000000} @@ -315,26 +294,24 @@ Subscribes to data changes of the ambient temperature sensor. If this API is cal ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD) +## sensor.on(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD) -on(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallback<MagneticFieldResponse>,options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>,options?: Options): void Subscribes to data changes of the magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.| - | callback | AsyncCallback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes| Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.| + | callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes| Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){ console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -344,26 +321,24 @@ Subscribes to data changes of the magnetic field sensor. If this API is called m ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED) +## sensor.on(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED) -on(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:AsyncCallback<MagneticFieldUncalibratedResponse>, options: Options): void +on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback<MagneticFieldUncalibratedResponse>, options: Options): void Subscribes to data changes of the uncalibrated magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.| - | callback | AsyncCallback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes| Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.| + | callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes| Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){ console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -376,26 +351,24 @@ Subscribes to data changes of the uncalibrated magnetic field sensor. If this AP ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY) +## sensor.on(SensorType.SENSOR_TYPE_ID_PROXIMITY) -on(type:sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback<ProximityResponse>,options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityResponse>,options?: Options): void Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.| - | callback | AsyncCallback<[ProximityResponse](#proximityresponse)> | Yes| Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.| + | callback | Callback<[ProximityResponse](#proximityresponse)> | Yes| Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){ console.info('Distance: ' + data.distance); }, {interval: 10000000} @@ -403,26 +376,24 @@ Subscribes to data changes of the proximity sensor. If this API is called multip ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY) +## sensor.on(SensorType.SENSOR_TYPE_ID_HUMIDITY) -on(type: sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback<HumidityResponse>,options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityResponse>,options?: Options): void Subscribes to data changes of the humidity sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.| - | callback | AsyncCallback<[HumidityResponse](#humidityresponse)> | Yes| Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.| + | callback | Callback<[HumidityResponse](#humidityresponse)> | Yes| Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){ console.info('Humidity: ' + data.humidity); }, {interval: 10000000} @@ -430,26 +401,24 @@ Subscribes to data changes of the humidity sensor. If this API is called multipl ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER) +## sensor.on(SensorType.SENSOR_TYPE_ID_BAROMETER) -on(type:sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback<BarometerResponse>,options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerResponse>,options?: Options): void Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.| - | callback | AsyncCallback<[BarometerResponse](#barometerresponse)> | Yes| Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.| + | callback | Callback<[BarometerResponse](#barometerresponse)> | Yes| Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){ console.info('Atmospheric pressure: ' + data.pressure); }, {interval: 10000000} @@ -457,26 +426,24 @@ Subscribes to data changes of the barometer sensor. If this API is called multip ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL) +## sensor.on(SensorType.SENSOR_TYPE_ID_HALL) -on(type: sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback<HallResponse>, options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>, options?: Options): void Subscribes to data changes of the Hall effect sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.| - | callback | AsyncCallback<[HallResponse](#hallresponse)> | Yes| Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.| + | callback | Callback<[HallResponse](#hallresponse)> | Yes| Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){ console.info('Status: ' + data.status); }, {interval: 10000000} @@ -484,26 +451,24 @@ Subscribes to data changes of the Hall effect sensor. If this API is called mult ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT) +## sensor.on(SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT) -on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback<LightResponse>, options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightResponse>, options?: Options): void Subscribes to data changes of the ambient light sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.| - | callback | AsyncCallback<[LightResponse](#lightresponse)> | Yes| Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.| + | callback | Callback<[LightResponse](#lightresponse)> | Yes| Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(data){ console.info(' Illumination: ' + data.intensity); }, {interval: 10000000} @@ -511,84 +476,105 @@ Subscribes to data changes of the ambient light sensor. If this API is called mu ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION) +## sensor.on(SensorType.SENSOR_TYPE_ID_ORIENTATION) -on(type: sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback<OrientationResponse>, options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<OrientationResponse>, options?: Options): void Subscribes to data changes of the orientation sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.| - | callback | AsyncCallback<[OrientationResponse](#orientationresponse)> | Yes| Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.| + | callback | Callback<[OrientationResponse](#orientationresponse)> | Yes| Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){ + console.info('The device rotates at an angle around the X axis: ' + data.beta); + console.info('The device rotates at an angle around the Y axis: ' + data.gamma); + console.info('The device rotates at an angle around the Z axis: ' + data.alpha); }, {interval: 10000000} ); ``` +## sensor.on(SensorType.SENSOR_TYPE_ID_HEART_RATE) + +on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRateResponse>, options?: Options): void + +Subscribes to only one data change of the heart rate sensor. + +**Required permissions**: ohos.permission.READ_HEALTH_DATA + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**. | +| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.| + +- Example -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR) +``` +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE,function(data){ + console.info("Heart rate: " + data.heartRate); +}, + {interval: 10000000} +); +``` -on(type:sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback:AsyncCallback<RotationVectorResponse>,options?: Options): void +## sensor.on(SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR) + +on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback<RotationVectorResponse>,options?: Options): void Subscribes to data changes of the rotation vector sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.| - | callback | AsyncCallback<[RotationVectorResponse](#rotationvectorresponse)> | Yes| Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.| + | callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes| Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(data){ console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); + console.info('Scalar quantity: ' + data.w); }, {interval: 10000000} ); ``` -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION) +## sensor.on(SensorType.SENSOR_TYPE_ID_WEAR_DETECTION) -on(type: sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallback<WearDetectionResponse>,options?: Options): void +on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearDetectionResponse>,options?: Options): void Subscribes to data changes of the wear detection sensor. If this API is called multiple times for the same application, the last call takes effect. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.| - | callback | AsyncCallback<[WearDetectionResponse](#weardetectionresponse)> | Yes| Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.| + | callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes| Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.| | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| - Example ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){ console.info('Wear status: ' + data.value); }, {interval: 10000000} @@ -596,25 +582,25 @@ Subscribes to data changes of the wear detection sensor. If this API is called m ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER) +## sensor.once(SensorType.SENSOR_TYPE_ID_ACCELEROMETER) -once(type: sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallback<AccelerometerResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<AccelerometerResponse>): void Subscribes to only one data change of the acceleration sensor. +**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.| - | callback | AsyncCallback<[AccelerometerResponse](#accelerometerresponse)> | Yes| One-shot callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.| + | callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes| One-shot callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){ console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -623,25 +609,25 @@ Subscribes to only one data change of the acceleration sensor. ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION) +## sensor.once(SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION) -once(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallback<LinearAccelerometerResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<LinearAccelerometerResponse>): void Subscribes to only one data change of the linear acceleration sensor. +**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.| - | callback | AsyncCallback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes| One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.| + | callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes| One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(data) { console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -650,25 +636,25 @@ Subscribes to only one data change of the linear acceleration sensor. ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED) +## sensor.once(SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED) -once(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:AsyncCallback<AccelerometerUncalibratedResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback<AccelerometerUncalibratedResponse>): void Subscribes to only one data change of the uncalibrated acceleration sensor. +**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.| - | callback | AsyncCallback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes| One-shot callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.| + | callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes| One-shot callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(data) { console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -680,25 +666,23 @@ Subscribes to only one data change of the uncalibrated acceleration sensor. ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY) +## sensor.once(SensorType.SENSOR_TYPE_ID_GRAVITY) -once(type:sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<GravityResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityResponse>): void Subscribes to only one data change of the gravity sensor. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.| - | callback | AsyncCallback<[GravityResponse](#gravityresponse)> | Yes| One-shot callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.| + | callback | Callback<[GravityResponse](#gravityresponse)> | Yes| One-shot callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(data) { console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -707,25 +691,25 @@ Subscribes to only one data change of the gravity sensor. ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE) +## sensor.once(SensorType.SENSOR_TYPE_ID_GYROSCOPE) -once(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback<GyroscopeResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeResponse>): void Subscribes to only one data change of the gyroscope sensor. +**Required permissions**: ohos.permission.GYROSCOPE (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.| - | callback | AsyncCallback<[GyroscopeResponse](#gyroscoperesponse)> | Yes| One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.| + | callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes| One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(data) { console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -734,25 +718,25 @@ Subscribes to only one data change of the gyroscope sensor. ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED) +## sensor.once(SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED) -once(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCallback<GyroscopeUncalibratedResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback<GyroscopeUncalibratedResponse>): void Subscribes to only one data change of the uncalibrated gyroscope sensor. +**Required permissions**: ohos.permission.GYROSCOPE (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.| - | callback | AsyncCallback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes| One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.| + | callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes| One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) { console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -764,125 +748,119 @@ Subscribes to only one data change of the uncalibrated gyroscope sensor. ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION) +## sensor.once(SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION) -once(type: sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback:AsyncCallback<SignificantMotionResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback<SignificantMotionResponse>): void Subscribes to only one data change of the significant motion sensor. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.| - | callback | AsyncCallback<[SignificantMotionResponse](#significantmotionresponse)> | Yes| One-shot callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.| + | callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes| One-shot callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) { console.info('Scalar data: ' + data.scalar); } ); ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION) +## sensor.once(SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION) -once(type:sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback:AsyncCallback<PedometerDetectResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback<PedometerDetectionResponse>): void Subscribes to only one data change of the pedometer detection sensor. +**Required permissions**: ohos.permission.ACTIVITY_MOTION + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.| - | callback | AsyncCallback<[PedometerDetectResponse](#pedometerdetectresponse)> | Yes| One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectResponse**.| + | callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes| One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) { console.info('Scalar data: ' + data.scalar); } ); ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER) +## sensor.once(SensorType.SENSOR_TYPE_ID_PEDOMETER) -once(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback<PedometerResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerResponse>): void Subscribes to only one data change of the pedometer sensor. +**Required permissions**: ohos.permission.ACTIVITY_MOTION + +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.| - | callback | AsyncCallback<[PedometerResponse](#pedometerresponse)> | Yes| One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.| + | callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes| One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) { console.info('Steps: ' + data.steps); } ); ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE) +## sensor.once(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE) -once(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallback<AmbientTemperatureResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback<AmbientTemperatureResponse>): void Subscribes to only one data change of the ambient temperature sensor. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.| - | callback | AsyncCallback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes| One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.| + | callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes| One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) { console.info('Temperature: ' + data.temperature); } ); ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD) +## sensor.once(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD) -once(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallback<MagneticFieldResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>): void Subscribes to only one data change of the magnetic field sensor. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.| - | callback | AsyncCallback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes| One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.| + | callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes| One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(data) { console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); @@ -891,302 +869,815 @@ Subscribes to only one data change of the magnetic field sensor. ``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED) +## sensor.once(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED) -once(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:AsyncCallback<MagneticFieldUncalibratedResponse>): void +once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback<MagneticFieldUncalibratedResponse>): void Subscribes to only one data change of the uncalibrated magnetic field sensor. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.| - | callback | AsyncCallback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes| One-shot callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.| + | callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes| One-shot callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.| - Example ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(error, data) { + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(data) { + console.info('X-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); + console.info('X-coordinate bias: ' + data.biasX); + console.info('Y-coordinate bias: ' + data.biasY); + console.info('Z-coordinate bias: ' + data.biasZ); + } + ); + ``` + + +## sensor.once(SensorType.SENSOR_TYPE_ID_PROXIMITY) + +once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityResponse>): void + +Subscribes to only one data change of the proximity sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.| + | callback | Callback<[ProximityResponse](#proximityresponse)> | Yes| One-shot callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(error, data) { if (error) { console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); return; } + console.info('Distance: ' + data.distance); + } + ); + ``` + + +## sensor.once(SensorType.SENSOR_TYPE_ID_HUMIDITY) + +once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityResponse>): void + +Subscribes to only one data change of the humidity sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.| + | callback | Callback<[HumidityResponse](#humidityresponse)> | Yes| One-shot callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) { + console.info('Humidity: ' + data.humidity); + } + ); + ``` + + +## sensor.once(SensorType.SENSOR_TYPE_ID_BAROMETER) + +once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerResponse>): void + +Subscribes to only one data change of the barometer sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.| + | callback | Callback<[BarometerResponse](#barometerresponse)> | Yes| One-shot callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) { + console.info('Atmospheric pressure: ' + data.pressure); + } + ); + ``` + + +## sensor.once(SensorType.SENSOR_TYPE_ID_HALL) + +once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>): void + +Subscribes to only one data change of the Hall effect sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.| + | callback | Callback<[HallResponse](#hallresponse)> | Yes| One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) { + console.info('Status: ' + data.status); + } + ); + ``` + + +## sensor.once(SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT) + +once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightResponse>): void + +Subscribes to only one data change of the ambient light sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.| + | callback | Callback<[LightResponse](#lightresponse)> | Yes| One-shot callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) { + console.info(' Illumination: ' + data.intensity); + } + ); + ``` + + +## sensor.once(SensorType.SENSOR_TYPE_ID_ORIENTATION) + +once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<OrientationResponse>): void + +Subscribes to only one data change of the orientation sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.| + | callback | Callback<[OrientationResponse](#orientationresponse)> | Yes| One-shot callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data) { + console.info('The device rotates at an angle around the X axis: ' + data.beta); + console.info('The device rotates at an angle around the Y axis: ' + data.gamma); + console.info('The device rotates at an angle around the Z axis: ' + data.alpha); + } + ); + ``` + + +## sensor.once(SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR) + +once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback<RotationVectorResponse>): void + +Subscribes to only one data change of the rotation vector sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.| + | callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes| One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) { console.info('X-coordinate component: ' + data.x); console.info('Y-coordinate component: ' + data.y); console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); + console.info('Scalar quantity: ' + data.w); + } + ); + ``` + + +## sensor.once(SensorType.SENSOR_TYPE_ID_HEART_RATE) + +once(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRateResponse>): void + +Subscribes to only one data change of the heart rate sensor. + +**Required permissions**: ohos.permission.READ_HEALTH_DATA + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.| + | callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes| One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(data) { + console.info("Heart rate: " + data.heartRate); + } + ); + ``` + + +## sensor.once(SensorType.SENSOR_TYPE_ID_WEAR_DETECTION) + +once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearDetectionResponse>): void + +Subscribes to only one data change of the wear detection sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.| + | callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes| One-shot callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) { + console.info("Wear status: "+ data.value); } ); ``` +## sensor.off(SensorType.SENSOR_TYPE_ID_ACCELEROMETER) + +off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback<AccelerometerResponse>): void + +Unsubscribes from sensor data changes. + +**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER**.| +| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.| + +- Example + +``` +function callback(data) { + console.info('x-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED) + +off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback<AccelerometerUncalibratedResponse>): void + +Unsubscribes from sensor data changes. + +**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.| +| callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.| + +- Example + +``` +function callback(data) { + console.info('X-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); + console.info('X-coordinate bias: ' + data.biasX); + console.info('Y-coordinate bias: ' + data.biasY); + console.info('Z-coordinate bias: ' + data.biasZ); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT) + +off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback<LightResponse>): void + +Unsubscribes from sensor data changes. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.| +| callback | Callback<[LightResponse](#lightresponse)> | Yes | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.| + +- Example + +``` +function callback(data) { + console.info(' Illumination: ' + data.intensity); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE) + +off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback<AmbientTemperatureResponse>): void + +Unsubscribes from sensor data changes. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.| +| callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.| + +- Example + +``` +function callback(data) { + console.info('Temperature: ' + data.temperature); +} +sensor.off( sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE) + +off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback<BarometerResponse>): void + +Unsubscribes from sensor data changes. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_BAROMETER**. | +| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.| + +- Example + +``` +function callback(data) { + console.info('Atmospheric pressure: ' + data.pressure); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_GRAVITY) + +off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback<GravityResponse>): void + +Unsubscribes from sensor data changes. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GRAVITY**. | +| callback | Callback<[GravityResponse](#gravityresponse)> | Yes | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.| + +- Example + +``` +function callback(data) { + console.info('X-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); +} +sensor.off( sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_GYROSCOPE) + +off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback<GyroscopeResponse>): void + +Unsubscribes from sensor data changes. + +**Required permissions**: ohos.permission.GYROSCOPE (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE**. | +| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.| + +- Example + +``` +function callback(data) { + console.info('X-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED) + +off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback<GyroscopeResponse>): void + +Unsubscribes from sensor data changes. + +**Required permissions**: ohos.permission.GYROSCOPE (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.| +| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.| + +- Example + +``` +function callback(data) { + console.info('X-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_HALL) + +off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback<HallResponse>): void + +Unsubscribes from sensor data changes. + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HALL**. | +| callback | Callback<[HallResponse](#hallresponse)> | Yes | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.| + +- Example + +``` +function callback(data) { + console.info('Status: ' + data.status); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_HEART_RATE) + +off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback<HeartRateResponse>): void + +Unsubscribes from sensor data changes. + +**Required permissions**: ohos.permission.READ_HEALTH_DATA + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype)[SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HEART_RATE**. | +| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.| + +- Example + +``` +function callback(data) { + console.info("Heart rate: " + data.heartRate); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_HUMIDITY) + +off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback<HumidityResponse>): void + +Unsubscribes from sensor data changes. + +**Required permission**: ohos.permission.READ_HEALTH_DATA (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor + +- Parameters + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HUMIDITY**. | +| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.| + +- Example + +``` +function callback(data) { + console.info('Humidity: ' + data.humidity); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION) -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY) +off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback<LinearAccelerometerResponse>): void -once(type: sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback<ProximityResponse>): void +Unsubscribes from sensor data changes. -Subscribes to only one data change of the proximity sensor. +**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.| - | callback | AsyncCallback<[ProximityResponse](#proximityresponse)> | Yes| One-shot callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.| + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.| +| callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes | Callback used to return the acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.| - Example - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Distance: ' + data.distance); - } - ); - ``` +``` +function callback(data) { + console.info('X-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback); +``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY) +## sensor.off(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD) -once(type: sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback<HumidityResponse>): void + off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback<MagneticFieldResponse>): void -Subscribes to only one data change of the humidity sensor. +Unsubscribes from sensor data changes. + +**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.| - | callback | AsyncCallback<[HumidityResponse](#humidityresponse)> | Yes| One-shot callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.| + +| Name | Type | Mandatory| Description | +| ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. | +| callbackcallback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.| - Example - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Humidity: ' + data.humidity); - } - ); - ``` +``` +function callback(data) { + console.info('X-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback); +``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER) +## sensor.off(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED) -once(type: sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback<BarometerResponse>): void + off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback<MagneticFieldUncalibratedResponse>): void -Subscribes to only one data change of the barometer sensor. +Unsubscribes from sensor data changes. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.| - | callback | AsyncCallback<[BarometerResponse](#barometerresponse)> | Yes| One-shot callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.| + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.| +| callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.| - Example - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Atmospheric pressure: ' + data.pressure); - } - ); - ``` +``` +function callback(data) { + console.info('X-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); + console.info('X-coordinate bias: ' + data.biasX); + console.info('Y-coordinate bias: ' + data.biasY); + console.info('Z-coordinate bias: ' + data.biasZ); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_ORIENTATION) -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL) + off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback<OrientationResponse>): void -once(type: sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback<HallResponse>): void +Unsubscribes from sensor data changes. -Subscribes to only one data change of the Hall effect sensor. +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.| - | callback | AsyncCallback<[HallResponse](#hallresponse)> | Yes| One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.| + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ORIENTATION**. | +| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.| - Example - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Status: ' + data.status); - } - ); - ``` +``` +function callback(data) { + console.info('The device rotates at an angle around the X axis: ' + data.beta); + console.info('The device rotates at an angle around the Y axis: ' + data.gamma); + console.info('The device rotates at an angle around the Z axis: ' + data.alpha); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); +``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT) +## sensor.off(SensorType.SENSOR_TYPE_ID_PEDOMETER) -once(type: sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback<LightResponse>): void +off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback<PedometerResponse>): void -Subscribes to only one data change of the ambient light sensor. +Unsubscribes from sensor data changes. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.| - | callback | AsyncCallback<[LightResponse](#lightresponse)> | Yes| One-shot callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.| + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER**. | +| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.| - Example - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info(' Illumination: ' + data.intensity); - } - ); - ``` +``` +function callback(data) { + console.info('Steps: ' + data.steps); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION) + +off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback<PedometerDetectionResponse>): void -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION) +Unsubscribes from sensor data changes. -once(type: sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback<OrientationResponse>): void +**Required permissions**: ohos.permission.ACTIVITY_MOTION -Subscribes to only one data change of the orientation sensor. +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.| - | callback | AsyncCallback<[OrientationResponse](#orientationresponse)> | Yes| One-shot callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.| + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.| +| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.| - Example - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` +``` +function callback(data) { + console.info('Scalar data: ' + data.scalar); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_PROXIMITY) -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR) +off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback<ProximityResponse>): void -once(type: sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: AsyncCallback<RotationVectorResponse>): void +Unsubscribes from sensor data changes. -Subscribes to only one data change of the rotation vector sensor. +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.| - | callback | AsyncCallback<[RotationVectorResponse](#rotationvectorresponse)> | Yes| One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.| + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PROXIMITY**. | +| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.| - Example - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` +``` +function callback(data) { + console.info('Distance: ' + data.distance); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback); +``` + +## sensor.off(SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR) -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE) +off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback<RotationVectorResponse>): void -once(type: sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: AsyncCallback<HeartRateResponse>): void +Unsubscribes from sensor data changes. -Subscribes to only one data change of the heart rate sensor. +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.| - | callback | AsyncCallback<[HeartRateResponse](#heartrateresponse)> | Yes| One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.| + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.| +| callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.| - Example - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info("Heart rate: " + data.heartRate); - } - ); - ``` +``` +function callback(data) { + console.info('X-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); + console.info('Scalar quantity: ' + data.w); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback); +``` -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION) +## sensor.off(SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION) -once(type: sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallback<WearDetectionResponse>): void +off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback<SignificantMotionResponse>): void -Subscribes to only one data change of the wear detection sensor. +Unsubscribes from sensor data changes. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.| - | callback | AsyncCallback<[WearDetectionResponse](#weardetectionresponse)> | Yes| One-shot callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.| + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.| +| callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.| - Example - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(error, data) { - if (error) { - console.error("Failed to register data, error code is" + error.code + ", message: " + error.message); - return; - } - console.info("Wear status: "+ data.value); - } - ); - ``` +``` +function callback(data) { + console.info('Scalar data: ' + data.scalar); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback); +``` -## sensor.off +## sensor.off(SensorType.SENSOR_TYPE_ID_WEAR_DETECTION) -off(type: SensorType, callback?: AsyncCallback<void>): void +off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback<WearDetectionResponse>): void Unsubscribes from sensor data changes. +**System capability**: SystemCapability.Sensors.Sensor + - Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | Yes| Type of the sensor to unsubscribe from.| - | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | [SensorType](#sensortype) | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.| +| callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.| - Example - ``` - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(error) { - if (error) { - console.error("Failed to unsubscribe from acceleration sensor data. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info("Succeeded in unsubscribing from acceleration sensor data."); - } - ); - ``` + +``` +function accCallback(data) { + console.info('Wear status: ' + data.value); +} +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback); +``` ## sensor.transformCoordinateSystem transformCoordinateSystem(inRotationVector: Array<number>, coordinates: CoordinatesOptions, callback: AsyncCallback<Array<number>>): void -Rotates a rotation vector so that it can represent the coordinate system in different ways. This method uses a callback to return the result. +Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses a callback to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | ---------------- | ----------------------------------------- | ---- | ---------------------- | - | inRotationVector | Array<number> | Yes| Rotation vector to rotate.| - | coordinates | [CoordinatesOptions](#coordinatesoptions) | Yes| Direction of the coordinate system.| - | callback | AsyncCallback<Array<number>> | Yes| Callback used to return the rotation vector after being rotated.| + | inRotationVector | Array<number> | Yes | Rotation vector to rotate. | + | coordinates | [CoordinatesOptions](#coordinatesoptions) | Yes | Direction of the coordinate system. | + | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation vector after being rotated.| - Example @@ -1207,18 +1698,20 @@ Rotates a rotation vector so that it can represent the coordinate system in diff transformCoordinateSystem(inRotationVector: Array<number>, coordinates: CoordinatesOptions): Promise<Array<number>> -Rotates a rotation vector so that it can represent the coordinate system in different ways. This method uses a promise to return the result. +Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses a promise to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | ---------------- | ----------------------------------------- | ---- | ---------------- | - | inRotationVector | Array<number> | Yes| Rotation vector to rotate.| - | coordinates | [CoordinatesOptions](#coordinatesoptions) | Yes| Direction of the coordinate system.| + | inRotationVector | Array<number> | Yes | Rotation vector to rotate. | + | coordinates | [CoordinatesOptions](#coordinatesoptions) | Yes | Direction of the coordinate system.| - Return value - | Type| Description| + | Type | Description | | ---------------------------------- | ---------------------- | | Promise<Array<number>> | Promise used to return the rotation vector after being converted.| @@ -1243,7 +1736,9 @@ Rotates a rotation vector so that it can represent the coordinate system in diff getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback<GeomagneticResponse>): void -Obtains the geomagnetic field of a geographic location. This method uses a callback to return the result. +Obtains the geomagnetic field of a geographic location. This API uses a callback to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters | Name| Type| Mandatory| Description| @@ -1270,7 +1765,9 @@ Obtains the geomagnetic field of a geographic location. This method uses a callb getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise<GeomagneticResponse> -Obtains the geomagnetic field of a geographic location. This method uses a promise to return the result. +Obtains the geomagnetic field of a geographic location. This API uses a promise to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters | Name| Type| Mandatory| Description| @@ -1299,15 +1796,17 @@ Obtains the geomagnetic field of a geographic location. This method uses a promi getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback<number>): void -Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This method uses a callback to return the result. +Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This API uses a callback to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | --------------- | --------------------------- | ---- | ------------------------------------- | - | seaPressure | number | Yes| Sea-level atmospheric pressure, in hPa.| - | currentPressure | number | Yes| Current atmospheric pressure at the altitude where the device is located, in hPa.| - | callback | AsyncCallback<number> | Yes| Callback used to return the altitude, in meters.| + | seaPressure | number | Yes | Sea-level atmospheric pressure, in hPa. | + | currentPressure | number | Yes | Current atmospheric pressure at the altitude where the device is located, in hPa.| + | callback | AsyncCallback<number> | Yes | Callback used to return the altitude, in meters. | - Example @@ -1326,18 +1825,20 @@ Obtains the altitude at which the device is located based on the sea-level atmos getAltitude(seaPressure: number, currentPressure: number): Promise<number> -Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This method uses a promise to return the result. +Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This API uses a promise to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | --------------- | ------ | ---- | ------------------------------------- | - | seaPressure | number | Yes| Sea-level atmospheric pressure, in hPa.| - | currentPressure | number | Yes| Atmospheric pressure at the altitude where the device is located, in hPa.| + | seaPressure | number | Yes | Sea-level atmospheric pressure, in hPa. | + | currentPressure | number | Yes | Atmospheric pressure at the altitude where the device is located, in hPa.| - Return value - | Type| Description| + | Type | Description | | --------------------- | ------------------------------------ | | Promise<number> | Promise used to return the altitude, in meters.| @@ -1357,14 +1858,16 @@ Obtains the altitude at which the device is located based on the sea-level atmos getGeomagneticDip(inclinationMatrix: Array<number>, callback: AsyncCallback<number>): void -Obtains the magnetic dip based on the inclination matrix. This method uses a callback to return the result. +Obtains the magnetic dip based on the inclination matrix. This API uses a callback to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | ----------------- | --------------------------- | ---- | ---------------------------- | - | inclinationMatrix | Array<number> | Yes| Inclination matrix.| - | callback | AsyncCallback<number> | Yes| Callback used to return the magnetic dip, in radians.| + | inclinationMatrix | Array<number> | Yes | Inclination matrix. | + | callback | AsyncCallback<number> | Yes | Callback used to return the magnetic dip, in radians.| - Example @@ -1383,17 +1886,19 @@ Obtains the magnetic dip based on the inclination matrix. This method uses a cal getGeomagneticDip(inclinationMatrix: Array<number>): Promise<number> -Obtains the magnetic dip based on the inclination matrix. This method uses a promise to return the result. +Obtains the magnetic dip based on the inclination matrix. This API uses a promise to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | ----------------- | ------------------- | ---- | -------------- | - | inclinationMatrix | Array<number> | Yes| Inclination matrix.| + | inclinationMatrix | Array<number> | Yes | Inclination matrix.| - Return value - | Type| Description| + | Type | Description | | --------------------- | ---------------------------- | | Promise<number> | Promise used to return the magnetic dip, in radians.| @@ -1412,15 +1917,17 @@ Obtains the magnetic dip based on the inclination matrix. This method uses a pro getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Array<number>, callback: AsyncCallback<Array<number>>): void -Obtains the angle change between two rotation matrices. This method uses a callback to return the result. +Obtains the angle change between two rotation matrices. This API uses a callback to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | --------------------- | ---------------------------------------- | ---- | --------------------------------- | - | currentRotationMatrix | Array<number> | Yes| Current rotation matrix.| - | preRotationMatrix | Array<number> | Yes| The other rotation matrix.| - | callback | AsyncCallback<Array<number>> | Yes| Callback used to return the angle change around the z, x, and y axes.| + | currentRotationMatrix | Array<number> | Yes | Current rotation matrix. | + | preRotationMatrix | Array<number> | Yes | The other rotation matrix. | + | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the angle change around the z, x, and y axes.| - Example @@ -1443,18 +1950,20 @@ Obtains the angle change between two rotation matrices. This method uses a callb getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Array<number>): Promise<Array<number>> -Obtains the angle change between two rotation matrices. This method uses a promise to return the result. +Obtains the angle change between two rotation matrices. This API uses a promise to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | --------------------- | ------------------- | ---- | ------------------ | - | currentRotationMatrix | Array<number> | Yes| Current rotation matrix.| - | preRotationMatrix | Array<number> | Yes| The other rotation matrix.| + | currentRotationMatrix | Array<number> | Yes | Current rotation matrix.| + | preRotationMatrix | Array<number> | Yes | Rotation matrix.| - Return value - | Type| Description| + | Type | Description | | ---------------------------------- | --------------------------------- | | Promise<Array<number>> | Promise used to return the angle change around the z, x, and y axes.| @@ -1477,14 +1986,16 @@ Obtains the angle change between two rotation matrices. This method uses a promi createRotationMatrix(rotationVector: Array<number>, callback: AsyncCallback<Array<number>>): void -Converts a rotation vector into a rotation matrix. This method uses a callback to return the result. +Converts a rotation vector into a rotation matrix. This API uses a callback to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | -------------- | ---------------------------------------- | ---- | -------------- | - | rotationVector | Array<number> | Yes| Rotation vector to convert.| - | callback | AsyncCallback<Array<number>> | Yes| Callback used to return the rotation matrix.| + | rotationVector | Array<number> | Yes | Rotation vector to convert.| + | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation matrix.| - Example @@ -1507,17 +2018,19 @@ Converts a rotation vector into a rotation matrix. This method uses a callback t createRotationMatrix(rotationVector: Array<number>): Promise<Array<number>> -Converts a rotation vector into a rotation matrix. This method uses a promise to return the result. +Converts a rotation vector into a rotation matrix. This API uses a promise to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | -------------- | ------------------- | ---- | -------------- | - | rotationVector | Array<number> | Yes| Rotation vector to convert.| + | rotationVector | Array<number> | Yes | Rotation vector to convert.| - Return value - | Type| Description| + | Type | Description | | ---------------------------------- | -------------- | | Promise<Array<number>> | Promise used to return the rotation matrix.| @@ -1540,14 +2053,16 @@ Converts a rotation vector into a rotation matrix. This method uses a promise to createQuaternion(rotationVector: Array<number>, callback: AsyncCallback<Array<number>>): void -Converts a rotation vector into a quaternion. This method uses a callback to return the result. +Converts a rotation vector into a quaternion. This API uses a callback to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | -------------- | ---------------------------------------- | ---- | -------------- | - | rotationVector | Array<number> | Yes| Rotation vector to convert.| - | callback | AsyncCallback<Array<number>> | Yes| Callback used to return the quaternion.| + | rotationVector | Array<number> | Yes | Rotation vector to convert.| + | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the quaternion. | - Example @@ -1570,17 +2085,19 @@ Converts a rotation vector into a quaternion. This method uses a callback to ret createQuaternion(rotationVector: Array<number>): Promise<Array<number>> -Converts a rotation vector into a quaternion. This method uses a promise to return the result. +Converts a rotation vector into a quaternion. This API uses a promise to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | -------------- | ------------------- | ---- | -------------- | - | rotationVector | Array<number> | Yes| Rotation vector to convert.| + | rotationVector | Array<number> | Yes | Rotation vector to convert.| - Return value - | Type| Description| + | Type | Description | | ---------------------------------- | ------------ | | Promise<Array<number>> | Promise used to return the quaternion.| @@ -1603,14 +2120,16 @@ Converts a rotation vector into a quaternion. This method uses a promise to retu getDirection(rotationMatrix: Array<number>, callback: AsyncCallback<Array<number>>): void -Obtains the device direction based on the rotation matrix. This method uses a callback to return the result. +Obtains the device direction based on the rotation matrix. This API uses a callback to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | -------------- | ---------------------------------------- | ---- | --------------------------------- | - | rotationMatrix | Array<number> | Yes| Rotation matrix.| - | callback | AsyncCallback<Array<number>> | Yes| Callback used to return the rotation angle around the z, x, and y axes.| + | rotationMatrix | Array<number> | Yes | Rotation matrix. | + | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation angle around the z, x, and y axes.| - Example @@ -1633,17 +2152,19 @@ Obtains the device direction based on the rotation matrix. This method uses a ca getDirection(rotationMatrix: Array<number>): Promise<Array<number>> -Obtains the device direction based on the rotation matrix. This method uses a promise to return the result. +Obtains the device direction based on the rotation matrix. This API uses a promise to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | -------------- | ------------------- | ---- | -------------- | - | rotationMatrix | Array<number> | Yes| Rotation matrix.| + | rotationMatrix | Array<number> | Yes | Rotation matrix.| - Return value - | Type| Description| + | Type | Description | | ---------------------------------- | --------------------------------- | | Promise<Array<number>> | Promise used to return the rotation angle around the z, x, and y axes.| @@ -1666,15 +2187,17 @@ Obtains the device direction based on the rotation matrix. This method uses a pr createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>, callback: AsyncCallback<RotationMatrixResponse>): void -Creates a rotation matrix based on the gravity vector and geomagnetic vector. This method uses a callback to return the result. +Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses a callback to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | ----------- | ------------------------------------------------------------ | ---- | -------------- | - | gravity | Array<number> | Yes| Gravity vector.| - | geomagnetic | Array<number> | Yes| Geomagnetic vector.| - | callback | AsyncCallback<[RotationMatrixResponse](#rotationmatrixresponse)> | Yes| Callback used to return the rotation matrix.| + | gravity | Array<number> | Yes | Gravity vector.| + | geomagnetic | Array<number> | Yes | Geomagnetic vector.| + | callback | AsyncCallback<[RotationMatrixResponse](#rotationmatrixresponse)> | Yes | Callback used to return the rotation matrix.| - Example @@ -1697,18 +2220,20 @@ Creates a rotation matrix based on the gravity vector and geomagnetic vector. Th createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>,): Promise<RotationMatrixResponse> -Creates a rotation matrix based on the gravity vector and geomagnetic vector. This method uses a promise to return the result. +Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses a promise to return the result. + +**System capability**: SystemCapability.Sensors.Sensor - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | ----------- | ------------------- | ---- | -------------- | - | gravity | Array<number> | Yes| Gravity vector.| - | geomagnetic | Array<number> | Yes| Geomagnetic vector.| + | gravity | Array<number> | Yes | Gravity vector.| + | geomagnetic | Array<number> | Yes | Geomagnetic vector.| - Return value - | Type| Description| + | Type | Description | | ------------------------------------------------------------ | -------------- | | Promise<[RotationMatrixResponse](#rotationmatrixresponse)> | Promise used to return the rotation matrix.| @@ -1731,6 +2256,8 @@ Creates a rotation matrix based on the gravity vector and geomagnetic vector. Th Enumerates the sensor types. +**System capability**: SystemCapability.Sensors.Sensor + | Name| Default Value| Description| | -------- | -------- | -------- | @@ -1761,6 +2288,8 @@ Enumerates the sensor types. Describes the timestamp of the sensor data. +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | timestamp | number | Yes| Yes| Timestamp when the sensor reports data.| @@ -1770,6 +2299,8 @@ Describes the timestamp of the sensor data. Describes the acceleration sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1782,6 +2313,8 @@ Describes the acceleration sensor data. It extends from [Response](#response). Describes the linear acceleration sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1794,6 +2327,8 @@ Describes the linear acceleration sensor data. It extends from [Response](#respo Describes the uncalibrated acceleration sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1809,6 +2344,8 @@ Describes the uncalibrated acceleration sensor data. It extends from [Response]( Describes the gravity sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1821,30 +2358,37 @@ Describes the gravity sensor data. It extends from [Response](#response). Describes the orientation sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| x | number | Yes| Yes| Rotation angle of the device around the x-axis, in rad.| -| y | number | Yes| Yes| Rotation angle of the device around the y-axis, in rad.| -| z | number | Yes| Yes| Rotation angle of the device around the z-axis, in rad.| +| alpha | number | Yes| Yes| Rotation angle of the device around the z-axis, in rad.| +| beta | number | Yes| Yes| Rotation angle of the device around the x-axis, in rad.| +| gamma | number | Yes| Yes| Rotation angle of the device around the y-axis, in rad.| ## RotationVectorResponse Describes the rotation vector sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | x | number | Yes| Yes| X-component of the rotation vector.| | y | number | Yes| Yes| Y-component of the rotation vector.| | z | number | Yes| Yes| Z-component of the rotation vector.| +| w | number | Yes| Yes| Scalar.| ## GyroscopeResponse Describes the gyroscope sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1857,6 +2401,8 @@ Describes the gyroscope sensor data. It extends from [Response](#response). Describes the uncalibrated gyroscope sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1872,6 +2418,8 @@ Describes the uncalibrated gyroscope sensor data. It extends from [Response](#re Describes the significant motion sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1882,6 +2430,8 @@ Describes the significant motion sensor data. It extends from [Response](#respon Describes the proximity sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1892,6 +2442,8 @@ Describes the proximity sensor data. It extends from [Response](#response). Describes the ambient light sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1902,6 +2454,8 @@ Describes the ambient light sensor data. It extends from [Response](#response). Describes the Hall effect sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1912,6 +2466,8 @@ Describes the Hall effect sensor data. It extends from [Response](#response). Describes the magnetic field sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1924,6 +2480,8 @@ Describes the magnetic field sensor data. It extends from [Response](#response). Describes the uncalibrated magnetic field sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1939,6 +2497,8 @@ Describes the uncalibrated magnetic field sensor data. It extends from [Response Describes the pedometer sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1949,16 +2509,20 @@ Describes the pedometer sensor data. It extends from [Response](#response). Describes the humidity sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | humidity | number | Yes| Yes| Ambient relative humidity, in a percentage (%).| -## PedometerDetectResponse +## PedometerDetectionResponse Describes the pedometer detection sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1969,6 +2533,8 @@ Describes the pedometer detection sensor data. It extends from [Response](#respo Describes the ambient temperature sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1979,6 +2545,8 @@ Describes the ambient temperature sensor data. It extends from [Response](#respo Describes the barometer sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1989,6 +2557,8 @@ Describes the barometer sensor data. It extends from [Response](#response). Describes the heart rate sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -1999,6 +2569,8 @@ Describes the heart rate sensor data. It extends from [Response](#response). Describes the wear detection sensor data. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -2009,6 +2581,8 @@ Describes the wear detection sensor data. It extends from [Response](#response). Describes the sensor data reporting frequency. +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Description| | -------- | -------- | -------- | | interval | number | Frequency at which a sensor reports data. The default value is 200,000,000 ns.| @@ -2017,26 +2591,32 @@ Describes the sensor data reporting frequency. Describes the response for setting the rotation matrix. -| Name| Type| Readable| Writable| Description| +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Readable| Writable| Description | | ----------- | ------------------- | ---- | ---- | ---------- | -| rotation | Array<number> | Yes| Yes| Rotation matrix.| -| inclination | Array<number> | Yes| Yes| Inclination matrix.| +| rotation | Array<number> | Yes | Yes | Rotation matrix.| +| inclination | Array<number> | Yes | Yes | Inclination matrix.| ## CoordinatesOptions Describes the coordinate options. -| Name| Type| Readable| Writable| Description| +**System capability**: SystemCapability.Sensors.Sensor + +| Name| Type| Readable| Writable| Description | | ---- | -------- | ---- | ---- | ----------- | -| x | number | Yes| Yes| X coordinate direction.| -| y | number | Yes| Yes| Y coordinate direction.| +| x | number | Yes | Yes | X coordinate direction.| +| y | number | Yes | Yes | Y coordinate direction.| ## GeomagneticResponse Describes a geomagnetic response object. It extends from [Response](#response). +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | x | number | Yes| Yes| North component of the geomagnetic field.| @@ -2047,9 +2627,12 @@ Describes a geomagnetic response object. It extends from [Response](#response). | levelIntensity | number | Yes| Yes| Horizontal intensity of the magnetic field vector field.| | totalIntensity | number | Yes| Yes| Total intensity of the magnetic field vector.| - ## LocationOptions +Describes the geographical location. + +**System capability**: SystemCapability.Sensors.Sensor + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | latitude | number | Yes| Yes| Latitude.| diff --git a/en/application-dev/reference/apis/js-apis-vibrator.md b/en/application-dev/reference/apis/js-apis-vibrator.md index f309d85801..55c4189e30 100644 --- a/en/application-dev/reference/apis/js-apis-vibrator.md +++ b/en/application-dev/reference/apis/js-apis-vibrator.md @@ -10,21 +10,16 @@ import vibrator from '@ohos.vibrator'; ``` -## System Capabilities - -SystemCapability.Sensors.MiscDevice - -## Required Permissions - -ohos.permission.VIBRATE - ## vibrator.vibrate vibrate(duration: number): Promise<void> +Triggers vibration with a specific duration. This API uses a promise to return the execution result. + +**Required permissions**: ohos.permission.VIBRATE (a system permission) -Triggers vibration with a specific duration. This method uses a promise to return the execution result. +**System capability**: SystemCapability.Sensors.MiscDevice - Parameters @@ -52,7 +47,11 @@ Triggers vibration with a specific duration. This method uses a promise to retur vibrate(duration: number, callback?: AsyncCallback<void>): void -Triggers vibration with a specific duration. This method uses a callback to return the execution result. +Triggers vibration with a specific duration. This API uses an asynchronous callback to return the execution result. + +**Required permissions**: ohos.permission.VIBRATE (a system permission) + +**System capability**: SystemCapability.Sensors.MiscDevice - Parameters | Name| Type| Mandatory| Description| @@ -76,7 +75,11 @@ Triggers vibration with a specific duration. This method uses a callback to retu vibrate(effectId: EffectId): Promise<void> -Triggers vibration with a specific effect. This method uses a promise to return the execution result. +Triggers vibration with a specific effect. This API uses a promise to return the execution result. + +**Required permissions**: ohos.permission.VIBRATE (a system permission) + +**System capability**: SystemCapability.Sensors.MiscDevice - Parameters | Name| Type| Mandatory| Description| @@ -102,7 +105,11 @@ Triggers vibration with a specific effect. This method uses a promise to return vibrate(effectId: EffectId, callback?: AsyncCallback<void>): void -Triggers vibration with a specific effect. This method uses a callback to return the execution result. +Triggers vibration with a specific effect. This API uses an asynchronous callback to return the execution result. + +**Required permissions**: ohos.permission.VIBRATE (a system permission) + +**System capability**: SystemCapability.Sensors.MiscDevice - Parameters | Name| Type| Mandatory| Description| @@ -126,7 +133,11 @@ Triggers vibration with a specific effect. This method uses a callback to return stop(stopMode: VibratorStopMode): Promise<void> -Stops the vibration based on the specified **stopMode**. This method uses a promise to return the execution result. If the specified **stopMode** is different from the mode used to trigger the vibration, this method fails to be called. +Stops the vibration based on the specified **stopMode**. This API uses a promise to return the execution result. If the specified **stopMode** is different from the mode used to trigger the vibration, this API fails to be called. + +**Required permissions**: ohos.permission.VIBRATE (a system permission) + +**System capability**: SystemCapability.Sensors.MiscDevice - Parameters | Name| Type| Mandatory| Description| @@ -152,7 +163,11 @@ Stops the vibration based on the specified **stopMode**. This method uses a prom stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void; -Stops the vibration based on the specified **stopMode**. This method uses an asynchronous callback to return the execution result. If the specified **stopMode** is different from the mode used to trigger the vibration, this method fails to be called. +Stops the vibration based on the specified **stopMode**. This API uses an asynchronous callback to return the execution result. If the specified **stopMode** is different from the mode used to trigger the vibration, this API fails to be called. + +**Required permissions**: ohos.permission.VIBRATE (a system permission) + +**System capability**: SystemCapability.Sensors.MiscDevice - Parameters | Name| Type| Mandatory| Description| @@ -176,6 +191,8 @@ Stops the vibration based on the specified **stopMode**. This method uses an asy Describes the vibration effect. +**System capability**: SystemCapability.Sensors.MiscDevice + | Name| Default Value| Description| | -------- | -------- | -------- | | EFFECT_CLOCK_TIMER | "haptic.clock.timer" | Vibration effect of the vibrator when a user adjusts the timer.| @@ -185,6 +202,8 @@ Describes the vibration effect. Describes the vibration mode to stop. +**System capability**: SystemCapability.Sensors.MiscDevice + | Name| Default Value| Description| | -------- | -------- | -------- | | VIBRATOR_STOP_MODE_TIME | "time" | The vibration to stop is in **duration** mode. This vibration is triggered with the parameter **duration** of the **number** type.| -- GitLab