运动传感器Motion sensors
These sensors measure acceleration forces and rotational forces along three axes. This category includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors.
You can access sensors available on the device and acquire raw sensor data by using the Androidsensor framework. The sensor framework provides several classes and interfaces that help you perform a widevariety of sensor-related tasks. For example, you can use the sensor framework to do the following:- Determine which sensors are available on a device.
- Determine an individual sensor's capabilities, such as its maximum range, manufacturer, power requirements, and resolution.
- Acquire raw sensor data and define the minimum rate at which you acquire sensor data.
- Register and unregister sensor event listeners that monitor sensor changes.
The Android sensor framework lets you access many types of sensors. Some of these sensors arehardware-based and some are software-based. Hardware-based sensors are physical components builtinto a handset or tablet device. They derive their data by directly measuring specific environmentalproperties, such as acceleration, geomagnetic field strength, or angular change. Software-basedsensors are not physical devices, although they mimic hardware-based sensors. Software-based sensorsderive their data from one or more of the hardware-based sensors and are sometimes called virtualsensors or synthetic sensors. The linear acceleration sensor and the gravity sensor are examples ofsoftware-based sensors. Table 1 summarizes the sensors that are supported by the Androidplatform.
Few Android-powered devices have every type of sensor. For example, most handset devices andtablets have an accelerometer and a magnetometer, but fewer devices havebarometers or thermometers. Also, a device can have more than one sensor of a given type. Forexample, a device can have two gravity sensors, each one having a different range.
TYPE_ACCELEROMETER |
Hardware | Measures the acceleration force in m/s2 that is applied to a device onall three physical axes (x, y, and z), including the force of gravity. | Motion detection (shake, tilt, etc.). |
TYPE_GYROSCOPE |
Hardware | Measures a device's rate of rotation in rad/s around each of the threephysical axes (x, y, and z). | Rotation detection (spin, turn, etc.). |
Sensor Framework
You can access these sensors and acquire raw sensor data by using the Android sensor framework.The sensor framework is part of the android.hardware
package and includes the followingclasses and interfaces:
- You can use this class to create an instance of the sensor service. This class providesvarious methods for accessing and listing sensors, registering and unregistering sensor eventlisteners, and acquiring orientation information. This class also provides several sensor constantsthat are used to report sensor accuracy, set data acquisition rates, and calibrate sensors.
- You can use this class to create an instance of a specific sensor. This class provides variousmethods that let you determine a sensor's capabilities.
SensorManager
Sensor
SensorEv