Skip to content

Most visited

Recently visited




public interface UserSensorDriver

Driver to interface with a user-connected sensor. This class is responsible for the actual I/O operations to talk to the sensor. Usage is to pass this to a UserSensor.Builder to create a UserSensor.


Public methods

abstract UserSensorReading read()

Reads the sensor.

default void setEnabled(boolean enabled)

Enables or disables the sensor.

Public methods


UserSensorReading read ()

Reads the sensor.

This will be called on a registered sensor when a new reading is needed, and only while the sensor is enabled. The implementation may block for a short time while making the necessary calls to communicate with the sensor.

If an exception is thrown, nothing will be reported to the framework and the sensor will be re-read on the next iteration.

UserSensorReading new UserSensorReading
IOException if reading fails


void setEnabled (boolean enabled)

Enables or disables the sensor.

If the sensor has a low power/sleep mode, this should be overridden to start sleep on disable and wake up on enable.

If an exception is thrown while enabling, the sensor will remain in disabled mode and will not be polled for readings. Exceptions thrown while disabling are ignored. In both cases, this method may attempt to re-enable in the future.

enabled boolean: true to enable the sensor, false to disable
IOException if sensor configuration fails
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)