oh_sensor.h

Overview

The oh_sensor.h file declares the APIs for operating sensors, including obtaining sensor information and subscribing to and unsubscribing from sensor data.

Library: libohsensor.so

System capability: SystemCapability.Sensors.Sensor

Since: 11

Related module: Sensor

Summary

Functions

Name Description
OH_Sensor_GetInfos(Sensor_Info **infos, uint32_t *count) Obtains information about all sensors on the device.
OH_Sensor_Subscribe(const Sensor_SubscriptionId *id, const Sensor_SubscriptionAttribute *attribute, const Sensor_Subscriber *subscriber) Subscribe to sensor data. The system will report sensor data to the subscriber at the specified frequency.
To subscribe to data of acceleration sensors, request the ohos.permission.ACCELEROMETER permission.
To subscribe to data of gyroscope sensors, request the ohos.permission.GYROSCOPE permission.
To subscribe to data of pedometer-related sensors, request the ohos.permission.ACTIVITY_MOTION permission.
To subscribe to data of health-related sensors, such as heart rate sensors, request the ohos.permission.READ_HEALTH_DATA permission. Otherwise, the subscription fails. You do not need to request any permission to subscribe to data of other types of sensors.
OH_Sensor_Unsubscribe(const Sensor_SubscriptionId *id, const Sensor_Subscriber *subscriber) Unsubscribes from sensor data.
To unsubscribe from data of acceleration sensors, request the ohos.permission.ACCELEROMETER permission.
To unsubscribe from data of gyroscope sensors, request the ohos.permission.GYROSCOPE permission.
To unsubscribe from data of pedometer-related sensors, request the ohos.permission.ACTIVITY_MOTION permission.
To unsubscribe from data of health-related sensors, request the ohos.permission.READ_HEALTH_DATA permission. Otherwise, the unsubscription fails. You do not need to request any permission to unsubscribe from data of other types of sensors.