Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
Sensors
Stay organized with collections
Save and categorize content based on your preferences.
Android sensors give applications access to a mobile device's underlying
physical sensors. They are data-providing virtual devices defined by sensors.h, the sensor Hardware Abstraction Layer (HAL).
What are Android sensors?
Android sensors are virtual devices that provide data coming from a set of
physical sensors: accelerometers, gyroscopes, magnetometers, barometer, humidity,
pressure, light, proximity and heart rate sensors.
Not included in the list of physical devices providing data are camera,
fingerprint sensor, microphone, and touch screen. These devices have their own
reporting mechanism; the separation is arbitrary, but in general, Android sensors
provide lower bandwidth data. For example, “100hz x 3 channels” for an
accelerometer versus “25hz x 8 MP x 3 channels” for a camera or “44kHz x 1
channel” for a microphone.
Android does not define how the different physical sensors are connected
to the system on chip (SoC).
- Often, sensor chips are connected to the SoC through a sensor hub, allowing
some low-power monitoring and processing of the data.
- Often, Inter-Integrated Circuit (I2C) or Serial Peripheral Interface
(SPI) is used as the transport mechanism.
- To reduce power consumption, some architectures are hierarchical, with
some minimal processing being done in the application-specific integrated
circuit (ASIC - like motion detection on the accelerometer chip), and more
is done in a microcontroller (like step detection in a sensor hub).
- It is up to the device manufacturer to choose an architecture based on
accuracy, power, price and package-size characteristics. See Sensor stack for more
information.
- Batching capabilities are an important consideration for power
optimization. See Batching for
more information.
Each Android sensor has a “type” representing how the sensor behaves and
what data it provides.
- The official Android Sensor
types are defined in sensors.h under the names SENSOR_TYPE_…
- The vast majority of sensors have an official sensor type.
- Those types are documented in the Android SDK.
- Behavior of sensors with those types are tested in the Android
Compatibility Test Suite (CTS).
- If a manufacturer integrates a new kind of sensor on an Android
device, the manufacturer can define its own temporary type to refer to
it.
- Those types are undocumented, so application developers are
unlikely to use them, either because they don’t know about them, or
know that they are rarely present (only on some devices from this
specific manufacturer).
- They are not tested by CTS.
- Once Android defines an official sensor type for this kind of sensor,
manufacturers must stop using their own temporary type and use the
official type instead. This way, the sensor will be used by more
application developers.
- The list of all sensors present on the device is reported by the HAL
implementation.
- There can be several sensors of the same type. For example, two
proximity sensors or two accelerometers.
- The vast majority of applications request only a single sensor of
a given type. For example, an application requesting the default
accelerometer will get the first accelerometer in the list.
- Sensors are often defined by wake-up and
non-wake-up
pairs, both sensors sharing the same type, but differing by their
wake-up characteristic.
Android sensors provide data as a series of sensor events.
Each event
contains:
The interpretation of the reported data depends on the sensor type. See
the sensor type
definitions for details on what data is reported for each sensor type.
Existing documentation
Targeted at developers
- Overview
- SDK reference
- Stack Overflow and tutorial websites
- Because sensors documentation was sometimes lacking, developers
resorted to Q&A websites like Stack Overflow to find answers.
- Some tutorial websites exist as well, but do not cover the latest
features like batching, significant motion and game rotation vectors.
- The answers over there are not always right, and show where more
documentation is needed.
Targeted at manufacturers
- Overview
- This Sensors
page and its sub-pages.
- Hardware abstraction layer (HAL)
- Android CDD (Compatibility Definition Document)
- /compatibility/android-cdd.pdf
- See sections relative to sensors.
- The CDD is lenient, so satisfying the CDD requirements is not enough to ensure
high quality sensors.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-06-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-18 UTC."],[],[],null,["# Sensors\n\nAndroid sensors give applications access to a mobile device's underlying\nphysical sensors. They are data-providing virtual devices defined by [sensors.h](https://android.googlesource.com/platform/hardware/libhardware/+/android16-release/include/hardware/sensors.h), the sensor Hardware Abstraction Layer (HAL).\n\nWhat are Android sensors?\n-------------------------\n\nAndroid sensors are virtual devices that provide data coming from a set of\nphysical sensors: accelerometers, gyroscopes, magnetometers, barometer, humidity,\npressure, light, proximity and heart rate sensors.\n\nNot included in the list of physical devices providing data are camera,\nfingerprint sensor, microphone, and touch screen. These devices have their own\nreporting mechanism; the separation is arbitrary, but in general, Android sensors\nprovide lower bandwidth data. For example, \"100hz x 3 channels\" for an\naccelerometer versus \"25hz x 8 MP x 3 channels\" for a camera or \"44kHz x 1\nchannel\" for a microphone.\n\nAndroid does not define how the different physical sensors are connected\nto the system on chip (SoC).\n\n- Often, sensor chips are connected to the SoC through a [sensor hub](/docs/core/interaction/sensors/sensor-stack#sensor_hub), allowing some low-power monitoring and processing of the data.\n- Often, Inter-Integrated Circuit (I2C) or Serial Peripheral Interface (SPI) is used as the transport mechanism.\n- To reduce power consumption, some architectures are hierarchical, with some minimal processing being done in the application-specific integrated circuit (ASIC - like motion detection on the accelerometer chip), and more is done in a microcontroller (like step detection in a sensor hub).\n- It is up to the device manufacturer to choose an architecture based on accuracy, power, price and package-size characteristics. See [Sensor stack](/docs/core/interaction/sensors/sensor-stack) for more information.\n- Batching capabilities are an important consideration for power optimization. See [Batching](/docs/core/interaction/sensors/batching) for more information.\n\nEach Android sensor has a \"type\" representing how the sensor behaves and\nwhat data it provides.\n\n- The official Android [Sensor\n types](/docs/core/interaction/sensors/sensor-types) are defined in [sensors.h](https://android.googlesource.com/platform/hardware/libhardware/+/android16-release/include/hardware/sensors.h) under the names SENSOR_TYPE_...\n - The vast majority of sensors have an official sensor type.\n - Those types are documented in the Android SDK.\n - Behavior of sensors with those types are tested in the Android Compatibility Test Suite (CTS).\n- If a manufacturer integrates a new kind of sensor on an Android device, the manufacturer can define its own temporary type to refer to it.\n - Those types are undocumented, so application developers are unlikely to use them, either because they don't know about them, or know that they are rarely present (only on some devices from this specific manufacturer).\n - They are not tested by CTS.\n - Once Android defines an official sensor type for this kind of sensor, manufacturers must stop using their own temporary type and use the official type instead. This way, the sensor will be used by more application developers.\n- The list of all sensors present on the device is reported by the HAL implementation.\n - There can be several sensors of the same type. For example, two proximity sensors or two accelerometers.\n - The vast majority of applications request only a single sensor of a given type. For example, an application requesting the default accelerometer will get the first accelerometer in the list.\n - Sensors are often defined by [wake-up](/docs/core/interaction/sensors/suspend-mode#wake-up_sensors) and [non-wake-up](/docs/core/interaction/sensors/suspend-mode#non-wake-up_sensors) pairs, both sensors sharing the same type, but differing by their wake-up characteristic.\n\nAndroid sensors provide data as a series of sensor events.\n\nEach [event](/docs/core/interaction/sensors/hal-interface#sensors_event_t)\ncontains:\n\n- a handle to the sensor that generated it\n- the timestamp at which the event was detected or measured, based on [`SystemClock.elapsedRealtimeNanos()`](https://developer.android.com/reference/android/os/SystemClock#elapsedRealtimeNanos())\n- and some data\n\nThe interpretation of the reported data depends on the sensor type. See\nthe [sensor type](/docs/core/interaction/sensors/sensor-types)\ndefinitions for details on what data is reported for each sensor type.\n\nExisting documentation\n----------------------\n\n### Targeted at developers\n\n- Overview\n - \u003chttps://developer.android.com/guide/topics/sensors/sensors_overview.html\u003e\n- SDK reference\n - \u003chttps://developer.android.com/reference/android/hardware/SensorManager\u003e\n - \u003chttps://developer.android.com/reference/android/hardware/SensorEventListener\u003e\n - \u003chttps://developer.android.com/reference/android/hardware/SensorEvent\u003e\n - \u003chttps://developer.android.com/reference/android/hardware/Sensor\u003e\n- Stack Overflow and tutorial websites\n - Because sensors documentation was sometimes lacking, developers resorted to Q\\&A websites like Stack Overflow to find answers.\n - Some tutorial websites exist as well, but do not cover the latest features like batching, significant motion and game rotation vectors.\n - The answers over there are not always right, and show where more documentation is needed.\n\n### Targeted at manufacturers\n\n- Overview\n - This [Sensors](/docs/core/interaction/sensors) page and its sub-pages.\n- Hardware abstraction layer (HAL)\n - [/platform/hardware/libhardware/+/android16-release/include/hardware/sensors.h](https://android.googlesource.com/platform/hardware/libhardware/+/android16-release/include/hardware/sensors.h)\n - Also known as \"sensors.h\"\n - The source of truth. First document to be updated when new features are developed.\n- Android CDD (Compatibility Definition Document)\n - [/compatibility/android-cdd.pdf](/static/docs/compatibility/android-cdd.pdf)\n - See sections relative to sensors.\n - The CDD is lenient, so satisfying the CDD requirements is not enough to ensure high quality sensors."]]