Sensor

NOTE

The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import sensor from '@ohos.sensor';

sensor.on

ACCELEROMETER

on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<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

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ACCELEROMETER.
callback Callback<AccelerometerResponse> Yes Callback used to return the acceleration sensor data. The reported data type in the callback is AccelerometerResponse.
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(data){
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
},
    {interval: 10000000}
);

LINEAR_ACCELERATION

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

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_LINEAR_ACCELERATION.
callback Callback<LinearAccelerometerResponse> Yes Callback used to return the linear acceleration sensor data. The reported data type in the callback is LinearAccelerometerResponse.
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(data){
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
},
    {interval: 10000000}
);

ACCELEROMETER_UNCALIBRATED

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

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED.
callback Callback<AccelerometerUncalibratedResponse> Yes Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is AccelerometerUncalibratedResponse.
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(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);
},
    {interval: 10000000}
);

GRAVITY

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GRAVITY.
callback Callback<GravityResponse> Yes Callback used to return the gravity sensor data. The reported data type in the callback is GravityResponse.
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(data){
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
},
    {interval: 10000000}
);

GYROSCOPE

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

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GYROSCOPE.
callback Callback<GyroscopeResponse> Yes Callback used to return the gyroscope sensor data. The reported data type in the callback is GyroscopeResponse.
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(data){
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
},
    {interval: 10000000}
);

GYROSCOPE_UNCALIBRATED

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

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED.
callback Callback<GyroscopeUncalibratedResponse> Yes Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is GyroscopeUncalibratedResponse.
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(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);
},
    {interval: 10000000}
);

SIGNIFICANT_MOTION

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_SIGNIFICANT_MOTION.
callback Callback<SignificantMotionResponse> Yes Callback used to return the significant motion sensor data. The reported data type in the callback is SignificantMotionResponse.
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(data){
    console.info('Scalar data: ' + data.scalar);
},
    {interval: 10000000}
);

PEDOMETER_DETECTION

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PEDOMETER_DETECTION.
callback Callback<PedometerDetectionResponse> Yes Callback used to return the pedometer detection sensor data. The reported data type in the callback is PedometerDetectionResponse.
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(data){
    console.info('Scalar data: ' + data.scalar);
},
    {interval: 10000000}
);

PEDOMETER

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PEDOMETER.
callback Callback<PedometerResponse> Yes Callback used to return the pedometer sensor data. The reported data type in the callback is PedometerResponse.
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(data){
    console.info('Steps: ' + data.steps);
},
    {interval: 10000000}
);

AMBIENT_TEMPERATURE

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_AMBIENT_TEMPERATURE.
callback Callback<AmbientTemperatureResponse> Yes Callback used to return the ambient temperature sensor data. The reported data type in the callback is AmbientTemperatureResponse.
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(data){
    console.info('Temperature: ' + data.temperature);
},
    {interval: 10000000}
);

MAGNETIC_FIELD

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_MAGNETIC_FIELD.
callback Callback<MagneticFieldResponse> Yes Callback used to return the magnetic field sensor data. The reported data type in the callback is MagneticFieldResponse.
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(data){
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
},
    {interval: 10000000}
);

MAGNETIC_FIELD_UNCALIBRATED

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED.
callback Callback<MagneticFieldUncalibratedResponse> Yes Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is MagneticFieldUncalibratedResponse.
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(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);
},
    {interval: 10000000}
);

PROXIMITY

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PROXIMITY.
callback Callback<ProximityResponse> Yes Callback used to return the proximity sensor data. The reported data type in the callback is ProximityResponse.
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(data){
    console.info('Distance: ' + data.distance);
},
    {interval: 10000000}
);

HUMIDITY

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_HUMIDITY.
callback Callback<HumidityResponse> Yes Callback used to return the humidity sensor data. The reported data type in the callback is HumidityResponse.
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(data){
    console.info('Humidity: ' + data.humidity);
},
    {interval: 10000000}
);

BAROMETER

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_BAROMETER.
callback Callback<BarometerResponse> Yes Callback used to return the barometer sensor data. The reported data type in the callback is BarometerResponse.
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(data){
    console.info('Atmospheric pressure: ' + data.pressure);
},
    {interval: 10000000}
);

HALL

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_HALL.
callback Callback<HallResponse> Yes Callback used to return the Hall effect sensor data. The reported data type in the callback is HallResponse.
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(data){
    console.info('Status: ' + data.status);
},
    {interval: 10000000}
);

AMBIENT_LIGHT

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_AMBIENT_LIGHT.
callback Callback<LightResponse> Yes Callback used to return the ambient light sensor data. The reported data type in the callback is LightResponse.
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(data){
    console.info(' Illumination: ' + data.intensity);
},
    {interval: 10000000}
);

ORIENTATION

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ORIENTATION.
callback Callback<OrientationResponse> Yes Callback used to return the orientation sensor data. The reported data type in the callback is OrientationResponse.
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(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}
);

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_HEART_RATE.
callback Callback<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_HEART_RATE,function(data){
    console.info("Heart rate: " + data.heartRate);
},
    {interval: 10000000}
);

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ROTATION_VECTOR.
callback Callback<RotationVectorResponse> Yes Callback used to return the rotation vector sensor data. The reported data type in the callback is RotationVectorResponse.
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(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}
);

WEAR_DETECTION

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_WEAR_DETECTION.
callback Callback<WearDetectionResponse> Yes Callback used to return the wear detection sensor data. The reported data type in the callback is WearDetectionResponse.
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(data){
    console.info('Wear status: ' + data.value);
},
    {interval: 10000000}
);

sensor.once

ACCELEROMETER

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

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ACCELEROMETER.
callback Callback<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(data){
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
  }
);

LINEAR_ACCELERATION

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

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_LINEAR_ACCELERATION.
callback Callback<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(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
  }
);

ACCELEROMETER_UNCALIBRATED

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

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED.
callback Callback<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(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);
  }
);

GRAVITY

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GRAVITY.
callback Callback<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(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
  }
);

GYROSCOPE

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

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GYROSCOPE.
callback Callback<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(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
  }
);

GYROSCOPE_UNCALIBRATED

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

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED.
callback Callback<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(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);
  }
);

SIGNIFICANT_MOTION

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_SIGNIFICANT_MOTION.
callback Callback<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(data) {
    console.info('Scalar data: ' + data.scalar);
  }
);

PEDOMETER_DETECTION

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PEDOMETER_DETECTION.
callback Callback<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(data) {
    console.info('Scalar data: ' + data.scalar);
  }
);

PEDOMETER

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PEDOMETER.
callback Callback<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(data) {
    console.info('Steps: ' + data.steps);
  }
);

AMBIENT_TEMPERATURE

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_AMBIENT_TEMPERATURE.
callback Callback<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(data) {
    console.info('Temperature: ' + data.temperature);
  }
);

MAGNETIC_FIELD

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_MAGNETIC_FIELD.
callback Callback<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(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
  }
);

MAGNETIC_FIELD_UNCALIBRATED

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED.
callback Callback<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(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);
  }
);

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PROXIMITY.
callback Callback<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);
  }
);

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_HUMIDITY.
callback Callback<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);
  }
);

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_BAROMETER.
callback Callback<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);
  }
);

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_HALL.
callback Callback<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);
  }
);

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_AMBIENT_LIGHT.
callback Callback<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);
  }
);

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ORIENTATION.
callback Callback<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);
  }
);

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ROTATION_VECTOR.
callback Callback<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('Scalar quantity: ' + data.w);
  }
);

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_HEART_RATE.
callback Callback<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);
  }
);

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 Yes Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_WEAR_DETECTION.
callback Callback<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

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 Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_ACCELEROMETER.
callback Callback<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);

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 Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED.
callback Callback<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);

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 Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_AMBIENT_LIGHT.
callback Callback<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);

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 Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_AMBIENT_TEMPERATURE.
callback Callback<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);

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 Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_BAROMETER.
callback Callback<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);

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 Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_GRAVITY.
callback Callback<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);

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 Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_GYROSCOPE.
callback Callback<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);

GYROSCOPE_UNCALIBRATED

off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback<GyroscopeUncalibratedResponse>): 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 Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED.
callback Callback<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);

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 Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_HALL.
callback Callback<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);

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 SensorTypeSensorType Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_HEART_RATE.
callback Callback<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);

HUMIDITY

off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback<HumidityResponse>): void

Unsubscribes from sensor data changes.

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_HUMIDITY.
callback Callback<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);

LINEAR_ACCELERATION

off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback<LinearAccelerometerResponse>): void

Unsubscribes from sensor data changes.

Required permissions: ohos.permission.ACCELEROMETER

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_LINEAR_ACCELERATION.
callback Callback<LinearAccelerometerResponse> Yes Callback used to return the acceleration sensor data. The reported data type in the callback is LinearAccelerometerResponse.

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_LINEAR_ACCELERATION, callback);

MAGNETIC_FIELD

off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback<MagneticFieldResponse>): void

Unsubscribes from sensor data changes.

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_MAGNETIC_FIELD.
callbackcallback Callback<MagneticFieldResponse> Yes Callback used to return the magnetic field sensor data. The reported data type in the callback is MagneticFieldResponse.

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_MAGNETIC_FIELD, callback);

MAGNETIC_FIELD_UNCALIBRATED

off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback<MagneticFieldUncalibratedResponse>): void

Unsubscribes from sensor data changes.

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED.
callback Callback<MagneticFieldUncalibratedResponse> Yes Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is MagneticFieldUncalibratedResponse.

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_MAGNETIC_FIELD_UNCALIBRATED, callback);

ORIENTATION

off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback<OrientationResponse>): void

Unsubscribes from sensor data changes.

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_ORIENTATION.
callback Callback<OrientationResponse> Yes Callback used to return the orientation sensor data. The reported data type in the callback is OrientationResponse.

Example

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);

PEDOMETER

off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback<PedometerResponse>): void

Unsubscribes from sensor data changes.

Required permissions: ohos.permission.ACTIVITY_MOTION

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_PEDOMETER.
callback Callback<PedometerResponse> Yes Callback used to return the pedometer sensor data. The reported data type in the callback is PedometerResponse.

Example

function callback(data) {
    console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);

PEDOMETER_DETECTION

off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback<PedometerDetectionResponse>): void

Unsubscribes from sensor data changes.

Required permissions: ohos.permission.ACTIVITY_MOTION

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_PEDOMETER_DETECTION.
callback Callback<PedometerDetectionResponse> Yes Callback used to return the pedometer detection sensor data. The reported data type in the callback is PedometerDetectionResponse.

Example

function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);

PROXIMITY

off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback<ProximityResponse>): void

Unsubscribes from sensor data changes.

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_PROXIMITY.
callback Callback<ProximityResponse> Yes Callback used to return the proximity sensor data. The reported data type in the callback is ProximityResponse.

Example

function callback(data) {
    console.info('Distance: ' + data.distance);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);

ROTATION_VECTOR

off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback<RotationVectorResponse>): void

Unsubscribes from sensor data changes.

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_ROTATION_VECTOR.
callback Callback<RotationVectorResponse> Yes Callback used to return the rotation vector sensor data. The reported data type in the callback is RotationVectorResponse.

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('Scalar quantity: ' + data.w);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);

SIGNIFICANT_MOTION

off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback<SignificantMotionResponse>): void

Unsubscribes from sensor data changes.

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
type SensorType Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_SIGNIFICANT_MOTION.
callback Callback<SignificantMotionResponse> Yes Callback used to return the significant motion sensor data. The reported data type in the callback is SignificantMotionResponse.

Example

function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);

WEAR_DETECTION

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 Yes Type of the sensor to unsubscribe from, which is SENSOR_TYPE_ID_WEAR_DETECTION.
callback Callback<WearDetectionResponse> Yes Callback used to return the wear detection sensor data. The reported data type in the callback is WearDetectionResponse.

Example

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 API uses a callback to return the result.

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
inRotationVector Array<number> Yes Rotation vector to rotate.
coordinates CoordinatesOptions Yes Direction of the coordinate system.
callback AsyncCallback<Array<number>> Yes Callback used to return the rotation vector after being rotated.

Example

sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(err, data) {
    if (err) {
        console.error("Operation failed. Error code: " + err.code + ", message: " + err.message);
        return;
    }
    console.info("Operation successed. Data obtained: " + data);
    for (var i=0; i < data.length; i++) {
        console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
    }
 })

sensor.transformCoordinateSystem

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 API uses a promise to return the result.

System capability: SystemCapability.Sensors.Sensor

Parameters

Name Type Mandatory Description
inRotationVector Array<number> Yes Rotation vector to rotate.
coordinates CoordinatesOptions Yes Direction of the coordinate system.

Return value

Type Description
Promise<Array<number>> Promise used to return the rotation vector after being rotated.

Example

const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3});
    promise.then((data) => {
        console.info("Operation successed.");
        for (var i=0; i < data.length; i++) {
            console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
        }
    }).catch((err) => {
           console.info("Operation failed");
})

sensor.getGeomagneticField

getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback<GeomagneticResponse>): void

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
locationOptions LocationOptions Yes Geographic location.
timeMillis number Yes Time for obtaining the magnetic declination, in milliseconds.
callback AsyncCallback<GeomagneticResponse> Yes Callback used to return the geomagnetic field.

Example

sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000, function(err, data)  {
    if (err) {
        console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message);
        return;
    }
    console.info('sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
});

sensor.getGeomagneticField

getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise<GeomagneticResponse>

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
locationOptions LocationOptions Yes Geographic location.
timeMillis number Yes Time for obtaining the magnetic declination, in milliseconds.

Return value

Type Description
Promise<GeomagneticResponse> Promise used to return the geomagnetic field.

Example

const promise = sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000);
    promise.then((data) => {
        console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
    }).catch((reason) => {
        console.info('Operation failed.');
})

sensor.getAltitude

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 API uses a callback to return the result.

System capability: SystemCapability.Sensors.Sensor

Parameters

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.
callback AsyncCallback<number> Yes Callback used to return the altitude, in meters.

Example

sensor.getAltitude(0, 200, function(err, data)  {
    if (err) {
        console.error(
"Operation failed. Error code: " + err.code + ", message: " + err.message);
        return;
    }
        console.info("Successed to get getAltitude interface get data: " + data);
});

sensor.getAltitude

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 API uses a promise to return the result.

System capability: SystemCapability.Sensors.Sensor

Parameters

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.

Return value

Type Description
Promise<number> Promise used to return the altitude, in meters.

Example

const promise = sensor.getAltitude(0, 200);
    promise.then((data) => {
        console.info(' sensor_getAltitude_Promise success', data);
    }).catch((err) => {
        console.error("Operation failed");
})

sensor.getGeomagneticDip

getGeomagneticDip(inclinationMatrix: Array<number>, callback: AsyncCallback<number>): void

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
inclinationMatrix Array<number> Yes Inclination matrix.
callback AsyncCallback<number> Yes Callback used to return the magnetic dip, in radians.

Example

sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
    if (err) {
        console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                      err.message);
        return;
    }
        console.info("Successed to get getGeomagneticDip interface get data: " + data);
})

sensor.getGeomagneticDip

getGeomagneticDip(inclinationMatrix: Array<number>): Promise<number>

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
inclinationMatrix Array<number> Yes Inclination matrix.

Return value

Type Description
Promise<number> Promise used to return the magnetic dip, in radians.

Example

const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]);
    promise.then((data) => {
        console.info(' getGeomagneticDip_promise successed', data);
    }).catch((err) => {
         console.error("Operation failed");
})

sensor. getAngleModify

getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Array<number>, callback: AsyncCallback<Array<number>>): void

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
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

sensor. getAngleModify([1,0,0,0,1,0,0,0,1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87], function(err, data)  {
    if (err) {
        console.error('Failed to register data, error code is: ' + err.code + ', message: ' + 
                      err.message);
        return;
    }
    for (var i=0; i < data.length; i++) {
        console.info("data[" + i + "]: " + data[i]);
    }
})

sensor. getAngleModify

getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Array<number>): Promise<Array<number>>

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
currentRotationMatrix Array<number> Yes Current rotation matrix.
preRotationMatrix Array<number> Yes Rotation matrix.

Return value

Type Description
Promise<Array<number>> Promise used to return the angle change around the z, x, and y axes.

Example

const promise = sensor.getAngleModify([1,0,0,0,1,0,0,0,1], [1,0,0,0,0.87,-0.50,0,0.50,0.87]);
    promise.then((data) => {
        console.info('getAngleModifiy_promise success');
        for (var i=0; i < data.length; i++) {
            console.info("data[" + i + "]: " + data[i]);
        }
    }).catch((reason) => {
        console.info("promise::catch", reason);
})

sensor.createRotationMatrix

createRotationMatrix(rotationVector: Array<number>, callback: AsyncCallback<Array<number>>): void

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
rotationVector Array<number> Yes Rotation vector to convert.
callback AsyncCallback<Array<number>> Yes Callback used to return the rotation matrix.

Example

sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) {
    if (err) {
        console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                      err.message);
        return;
    }
    for (var i=0; i < data.length; i++) {
        console.info("data[" + i + "]: " + data[i]);
    }
})

sensor.createRotationMatrix

createRotationMatrix(rotationVector: Array<number>): Promise<Array<number>>

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
rotationVector Array<number> Yes Rotation vector to convert.

Return value

Type Description
Promise<Array<number>> Promise used to return the rotation matrix.

Example

const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
    promise.then((data) => {
        console.info('createRotationMatrix_promise success');
        for (var i=0; i < data.length; i++) {
            console.info("data[" + i + "]: " + data[i]);
        }
    }).catch((reason) => {
        console.info("promise::catch", reason);
})	

sensor.createQuaternion

createQuaternion(rotationVector: Array<number>, callback: AsyncCallback<Array<number>>): void

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
rotationVector Array<number> Yes Rotation vector to convert.
callback AsyncCallback<Array<number>> Yes Callback used to return the quaternion.

Example

sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data)  {
    if (err) {
        console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                      err.message);
        return;
    }
    for (var i=0; i < data.length; i++) {
        console.info("data[" + i + "]: " + data[i]);
    }
})

sensor.createQuaternion

createQuaternion(rotationVector: Array<number>): Promise<Array<number>>

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
rotationVector Array<number> Yes Rotation vector to convert.

Return value

Type Description
Promise<Array<number>> Promise used to return the quaternion.

Example

const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]);
    promise.then((data) => {
        console.info('createQuaternion_promise successed');
        for (var i=0; i < data.length; i++) {
            console.info("data[" + i + "]: " + data[i]);
        }
    }).catch((err) => {
        console.info('promise failed');
})

sensor.getDirection

getDirection(rotationMatrix: Array<number>, callback: AsyncCallback<Array<number>>): void

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
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

sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
    if (err) {
        console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
                      err.message);
        return;
    }
    for (var i = 1; i < data.length; i++) {
        console.info("sensor_getDirection_callback" + data[i]);
    }
})

sensor.getDirection

getDirection(rotationMatrix: Array<number>): Promise<Array<number>>

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
rotationMatrix Array<number> Yes Rotation matrix.

Return value

Type Description
Promise<Array<number>> Promise used to return the rotation angle around the z, x, and y axes.

Example

const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
    promise.then((data) => {
        console.info('sensor_getAltitude_Promise success', data);
        for (var i = 1; i < data.length; i++) {
            console.info("sensor_getDirection_promise" + data[i]);
        }
    }).catch((err) => {
        console.info('promise failed');
})

sensor.createRotationMatrix

createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>, callback: AsyncCallback<RotationMatrixResponse>): void

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
gravity Array<number> Yes Gravity vector.
geomagnetic Array<number> Yes Geomagnetic vector.
callback AsyncCallback<RotationMatrixResponse> Yes Callback used to return the rotation matrix.

Example

sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data)  {
    if (err) {
        console.error('error code is: ' + err.code + ', message: ' + err.message);
        return;
    }
    console.info(JSON.stringify(data));
})

sensor.createRotationMatrix

createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>,): Promise<RotationMatrixResponse>

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
gravity Array<number> Yes Gravity vector.
geomagnetic Array<number> Yes Geomagnetic vector.

Return value

Type Description
Promise<RotationMatrixResponse> Promise used to return the rotation matrix.

Example

const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
    promise.then((data) => {
        console.info(JSON.stringify(data));
    }).catch((err) => {
        console.info('promise failed');
})

SensorType

Enumerates the sensor types.

System capability: SystemCapability.Sensors.Sensor

Name Default Value Description
SENSOR_TYPE_ID_ACCELEROMETER 1 Acceleration sensor.
SENSOR_TYPE_ID_GYROSCOPE 2 Gyroscope sensor.
SENSOR_TYPE_ID_AMBIENT_LIGHT 5 Ambient light sensor.
SENSOR_TYPE_ID_MAGNETIC_FIELD 6 Magnetic field sensor.
SENSOR_TYPE_ID_BAROMETER 8 Barometer sensor.
SENSOR_TYPE_ID_HALL 10 Hall effect sensor.
SENSOR_TYPE_ID_PROXIMITY 12 Proximity sensor.
SENSOR_TYPE_ID_HUMIDITY 13 Humidity sensor.
SENSOR_TYPE_ID_ORIENTATION 256 Orientation sensor.
SENSOR_TYPE_ID_GRAVITY 257 Gravity sensor.
SENSOR_TYPE_ID_LINEAR_ACCELERATION 258 Linear acceleration sensor.
SENSOR_TYPE_ID_ROTATION_VECTOR 259 Rotation vector sensor.
SENSOR_TYPE_ID_AMBIENT_TEMPERATURE 260 Ambient temperature sensor.
SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED 261 Uncalibrated magnetic field sensor.
SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED 263 Uncalibrated gyroscope sensor.
SENSOR_TYPE_ID_SIGNIFICANT_MOTION 264 Significant motion sensor.
SENSOR_TYPE_ID_PEDOMETER_DETECTION 265 Pedometer detection sensor.
SENSOR_TYPE_ID_PEDOMETER 266 Pedometer sensor.
SENSOR_TYPE_ID_HEART_RATE 278 Heart rate sensor.
SENSOR_TYPE_ID_WEAR_DETECTION 280 Wear detection sensor.
SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED 281 Uncalibrated acceleration sensor.

Response

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.

AccelerometerResponse

Describes the acceleration sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
x number Yes Yes Acceleration along the x-axis of the device, in m/s2.
y number Yes Yes Acceleration along the y-axis of the device, in m/s2.
z number Yes Yes Acceleration along the z-axis of the device, in m/s2.

LinearAccelerometerResponse

Describes the linear acceleration sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
x number Yes Yes Linear acceleration along the x-axis of the device, in m/s2.
y number Yes Yes Linear acceleration along the y-axis of the device, in m/s2.
z number Yes Yes Linear acceleration along the z-axis of the device, in m/s2.

AccelerometerUncalibratedResponse

Describes the uncalibrated acceleration sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
x number Yes Yes Uncalibrated acceleration along the x-axis of the device, in m/s2.
y number Yes Yes Uncalibrated acceleration along the y-axis of the device, in m/s2.
z number Yes Yes Uncalibrated acceleration along the z-axis of the device, in m/s2.
biasX number Yes Yes Uncalibrated acceleration bias along the x-axis of the device, in m/s2.
biasY number Yes Yes Uncalibrated acceleration bias along the y-axis of the device, in m/s2.
biasZ number Yes Yes Uncalibrated acceleration bias along the z-axis of the device, in m/s2.

GravityResponse

Describes the gravity sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
x number Yes Yes Gravitational acceleration along the x-axis of the device, in m/s2.
y number Yes Yes Gravitational acceleration along the y-axis of the device, in m/s2.
z number Yes Yes Gravitational acceleration along the z-axis of the device, in m/s2.

OrientationResponse

Describes the orientation sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
alpha number Yes Yes Rotation angle of the device around the z-axis, in degrees.
beta number Yes Yes Rotation angle of the device around the x-axis, in degrees.
gamma number Yes Yes Rotation angle of the device around the y-axis, in degrees.

RotationVectorResponse

Describes the rotation vector sensor data. It extends from 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.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
x number Yes Yes Angular velocity of rotation around the x-axis of the device, in rad/s.
y number Yes Yes Angular velocity of rotation around the y-axis of the device, in rad/s.
z number Yes Yes Angular velocity of rotation around the z-axis of the device, in rad/s.

GyroscopeUncalibratedResponse

Describes the uncalibrated gyroscope sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
x number Yes Yes Uncalibrated angular velocity of rotation around the x-axis of the device, in rad/s.
y number Yes Yes Uncalibrated angular velocity of rotation around the y-axis of the device, in rad/s.
z number Yes Yes Uncalibrated angular velocity of rotation around the z-axis of the device, in rad/s.
biasX number Yes Yes Uncalibrated angular velocity bias of rotation around the x-axis of the device, in rad/s.
biasY number Yes Yes Uncalibrated angular velocity bias of rotation around the y-axis of the device, in rad/s.
biasZ number Yes Yes Uncalibrated angular velocity bias of rotation around the z-axis of the device, in rad/s.

SignificantMotionResponse

Describes the significant motion sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
scalar number Yes Yes Intensity of a motion. This parameter specifies whether a device has a significant motion on three physical axes (X, Y, and Z). The value 0 means that the device does not have a significant motion, and 1 means the opposite.

ProximityResponse

Describes the proximity sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
distance number Yes Yes Proximity between the visible object and the device monitor. The value 0 means the two are close to each other, and 1 means that they are far away from each other.

LightResponse

Describes the ambient light sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
intensity number Yes Yes Illumination, in lux.

HallResponse

Describes the Hall effect sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
status number Yes Yes Hall effect sensor status. This parameter specifies whether a magnetic field exists around a device. The value 0 means that a magnetic field does not exist, and a value greater than 0 means the opposite.

MagneticFieldResponse

Describes the magnetic field sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
x number Yes Yes Magnetic field strength on the x-axis, in μT.
y number Yes Yes Magnetic field strength on the y-axis, in μT.
z number Yes Yes Magnetic field strength on the z-axis, in μT.

MagneticFieldUncalibratedResponse

Describes the uncalibrated magnetic field sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
x number Yes Yes Uncalibrated magnetic field strength on the x-axis, in μT.
y number Yes Yes Uncalibrated magnetic field strength on the y-axis, in μT.
z number Yes Yes Uncalibrated magnetic field strength on the z-axis, in μT.
biasX number Yes Yes Bias of the uncalibrated magnetic field strength on the x-axis, in μT.
biasY number Yes Yes Bias of the uncalibrated magnetic field strength on the y-axis, in μT.
biasZ number Yes Yes Bias of the uncalibrated magnetic field strength on the z-axis, in μT.

PedometerResponse

Describes the pedometer sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
steps number Yes Yes Number of steps a user has walked.

HumidityResponse

Describes the humidity sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
humidity number Yes Yes Ambient relative humidity, in a percentage (%).

PedometerDetectionResponse

Describes the pedometer detection sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
scalar number Yes Yes Pedometer detection. This parameter specifies whether a user takes a step. The value 0 means that the user does not take a step, and 1 means that the user takes a step.

AmbientTemperatureResponse

Describes the ambient temperature sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
temperature number Yes Yes Ambient temperature, in degree Celsius.

BarometerResponse

Describes the barometer sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
pressure number Yes Yes Atmospheric pressure, in pascal.

HeartRateResponse

Describes the heart rate sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
heartRate number Yes Yes Heart rate, in beats per minute (bpm).

WearDetectionResponse

Describes the wear detection sensor data. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
value number Yes Yes Whether the device is being worn. The value 1 means that the device is being worn, and 0 means the opposite.

Options

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.

RotationMatrixResponse

Describes the response for setting the rotation matrix.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
rotation Array<number> Yes Yes Rotation matrix.
inclination Array<number> Yes Yes Inclination matrix.

CoordinatesOptions

Describes the coordinate options.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
x number Yes Yes X coordinate direction.
y number Yes Yes Y coordinate direction.

GeomagneticResponse

Describes a geomagnetic response object. It extends from Response.

System capability: SystemCapability.Sensors.Sensor

Name Type Readable Writable Description
x number Yes Yes North component of the geomagnetic field.
y number Yes Yes East component of the geomagnetic field.
z number Yes Yes Vertical component of the geomagnetic field.
geomagneticDip number Yes Yes Magnetic dip, also called magnetic inclination, which is the angle measured from the horizontal plane to the magnetic field vector.
deflectionAngle number Yes Yes Magnetic declination, which is the angle between true north (geographic north) and the magnetic north (the horizontal component of the field).
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.
longitude number Yes Yes Longitude.
altitude number Yes Yes Altitude.