Sensors

Most Android-powered devices have built-in sensors that measure motion, orientation, and various environmental conditions. These sensors are capable of providing raw data with high precision and accuracy, and are useful if you want to monitor three-dimensional device movement or positioning, or you want to monitor changes in the ambient environment near a device. For example, a game might track readings from a device's gravity sensor to infer complex user gestures and motions, such as tilt, shake, rotation, or swing. Likewise, a weather application might use a device's temperature sensor and humidity sensor to calculate and report the dewpoint, or a travel application might use the geomagnetic field sensor and accelerometer to report a compass bearing.

The Android platform supports three broad categories of sensors:

  • Motion sensors

    These sensors measure acceleration forces and rotational forces along three axes. This category includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors.

  • Environmental sensors

    These sensors measure various environmental parameters, such as ambient air temperature and pressure, illumination, and humidity. This category includes barometers, photometers, and thermometers.

  • Position sensors

    These sensors measure the physical position of a device. This category includes orientation sensors and magnetometers.

To access these sensors, you can use the Android sensor framework. The sensor framework provides several classes and interfaces that help you perform a wide variety of sensor-related tasks. To learn more about the framework and the sensors that are supported on the Android system, read the following documents:

Sensors Overview
Learn how to list the sensors that are on a device, set up sensor event listeners, and acquire sensor data. Also learn best practices for accessing and using sensors.
Motion Sensors
Learn how to use the sensors that provide acceleration data, such as the accelerometer, gravity sensor, and linear acceleration sensor. Also learn how to use the sensors that provide rotational data, such as gyroscopes and rotational vector sensors.
Position Sensors
Learn how to use the sensors that provide orientation and compass data, such as the orientation sensor and the geomagnetic field sensor.
Environment Sensors
Learn how to use the sensors that provide environmental data, such as the light, humidity, pressure, temperature, and proximity sensors.
↑ Go to top