Sensors on Android


Sensors on Android

From GPS or network location to accelerometer, gyroscope, temperature, barometer, and more, use the device's sensors to provide extensive location and motion features to your app.

Sensors Overview

Sensors that monitor motion, orientation, and different environmental variables are integrated into most Android-powered smartphones. These sensors may provide raw data with great precision and accuracy, making them helpful for monitoring three-dimensional device movement or location, as well as changes in the ambient environment around a device. A game may, for example, use data from a device's gravity sensor to infer sophisticated user gestures and actions like tilt, shaking, rotation, and swing.

Refer to the following resources for more information:

  • Sensors.
  • Sensors that detect movement.
  • Sensors of Position.
  • Demos of the Environment Sensors API (OS - RotationVectorDemo).

The Android OS recognises three types of sensors:

  • Sensors that detect movement.
  • Along three axes, these sensors monitor acceleration and rotational forces. Accelerometers, gravity sensors, gyroscopes, and rotating vector sensors all fall within this group.
  • Sensors for the environment.
  • Various environmental factors, such as ambient air temperature and pressure, light, and humidity, are measured by these sensors. Barometers, photometers, and thermometers all fall under this category.
  • Sensors that monitor a device's physical location are known as position sensors. Magnetometers and orientation sensors are included in this category.

Sensors that detect movement

The Android platform has a number of sensors that may be used to track a device's movement.

The sensor topologies that are feasible differ depending on the sensor type:

  • The sensors for gravity, linear acceleration, rotation vector, significant motion, step counter, and step detector are all hardware-based.
  • Hardware-based accelerometer and gyroscope sensors are always used.

Sensors that detect movement

The geomagnetic field sensor and the accelerometer are two sensors included in the Android platform that may be used to detect a device's location. The Android platform also has a sensor for determining how near a device's face is to an item (known as the proximity sensor). The proximity sensor and the geomagnetic field sensor are both hardware-based sensors. A geomagnetic field sensor is included by most mobile and tablet makers. A proximity sensor is also commonly included by handset makers to detect when a device is held close to a user's face (for example, during a phone call). The information from the device's accelerometer and geomagnetic field sensor may be used to determine a device's orientation.

Sensors that monitor the environment

Four sensors are included with the Android platform, allowing you to monitor various environmental characteristics. These sensors may be used to measure relative ambient humidity, illuminance, ambient pressure, and ambient temperature in close proximity to an Android smartphone. All four environment sensors are hardware-based, and they can only be used if a device maker has included them in the design. Environment sensors are not always present on devices, with the exception of the light sensor, which is used by most device makers to adjust screen brightness. As a result, it's critical to double-check if an environment sensor exists at runtime before attempting to collect data from it.