The Sensors API lets you to read raw sensor data in your app in real time. Use this API to:
- List data sources available on the device and on companion devices.
- Register listeners to receive raw sensor data.
- Unregister listeners to stop receiving raw sensor data.
The Sensors API does not automatically store sensor readings in the fitness store, and sensor registrations created with the Sensors API are not persisted when the system restarts. You typically use the Recording API to record data in the background with persistent subscriptions, and you use the Sensors API to display or process sensor readings in real time. In many cases, you use both of these APIs in your app.
List available data sources
To obtain a list of all available data sources on the device and on companion
devices, use the
To get information about the device for a data source, use the
method. The device information is useful to distinguish from similar
sensors on different devices, show the device information from a sensor to the
user, or process data differently depending on the device. For example, you may
be interested in reading data specifically from the a sensor on a wearable
device but not from the same type of sensor on the phone.
To get a
instance for the device that is running your activity, use the
static method. This is useful when you want to check if a data source is on the
same device that your app is running on.
Add a listener
To add a listener to receive raw data of a particular fitness data type or from
a specific data source, use the
Remove a listener
To remove a listener from raw data updates, use the