Sensor framework
By using the android framework, you can access these sensors and obtain raw sensor data. The sensor framework is part of the android. hardware package and includes the following classes and interfaces:
1. sensormanager
Use this class to create a sensor service instance. This class provides a variety of methods for accessing and listening to sensors. It also provides several sensor constants for reporting the accuracy of the sensor, setting the data acquisition rate, and calibration the sensor.
2. Sensor
Use this class to create an instance of a special sensor. It provides various methods for determining the sensor capability.
3. sensorevent
The system uses this class to create a sensor event object, which provides information about sensor events. A sensor event object contains the following information:
A. Raw sensor data;
B. types of sensors that generate events;
C. Data accuracy;
D. Event timestamp.
4. sensoreventlistener
Use this interface to create two callback methods, which receive notifications (sensor events) when the sensor value or accuracy changes ).
In typical applications, you use sensor-related APIs to perform two basic tasks:
1. Identify sensors and sensor capabilities
Identifying sensors and sensor capabilities during operation is helpful for determining whether your application has functionality dependent on special sensor types and capabilities. For example, you may want to identify all the sensors on the current device and disable all functions that are not supported by the dependent sensors. Similarly, you may want to identify all the sensors of the given type so that you can select the sensors suitable for your application.
2. Monitor sensor events
Monitoring sensor events is a way to obtain raw sensor data. A sensor event occurs every time it detects a change in its measurement parameters. Sensor events provide four types of information:
A. Name of the sensor that triggered the event;
B. Event timestamp;
C. Event precision;
D. Raw sensor data that triggers the event.