The Client supports adding and removing listeners to live data streams from any available
data source. It also allows for listening on a DataType,
in which case the best available data source (or a combination of them) is used.

The Sensors Client should be used whenever live updates from a sensor stream need to be
pushed to the application (for instance, to update a UI). The History
Client can be used to query historical data in a pull-based model for scenarios
where latency isn't critical.

The Sensors Client should be accessed from the Fitness entry
point. Example:

Public Methods

Adds a data point listener
to a sensor data source. This method can be called to listen on live updates from a
particular data source, or data type (in which case a default data source is used).

Once the add request succeeds, new data points in the data stream are delivered to
the specified listener. Historic data is not delivered, but can be queried via the
History
Client. When the application is closing, or once live data is no longer
needed, the listener should be removed. If necessary, the Recording
Client can be used to persist data for later querying when the application
is re-opened in a battery-efficient manner.

This method can be called several times with the same listener to change the desired
sampling rate.

Parameters

request

request specifying the desired data source or data type, as well as the desired
parameters for the add request

listener

the listener that will be used to respond to events. The listener object should
be saved, since it can be used to remove the registration when live events are no
longer needed

Throws

Adds a PendingIntent
listener to a sensor data source. This method can be called to listen on live updates
from a particular data source, or a data type (in which case a default data source is
used).

Once the add request succeeds, new data points in the data stream are delivered to
the specified intent. Historic data is not delivered, but can be queried via the
History
Client.

Unlike
add(SensorRequest, OnDataPointListener), which takes a listener and is
intended for fast sampling rates while the application is on the foreground, this
method is intended for slower sampling rates without the need for an always-on
service.

The application specifies a PendingIntent callback (typically an IntentService)
which will be called when new data points are available in the requested stream. When
the PendingIntent is called, the application can use
extract(android.content.Intent) to extract the DataPoint from the intent.
See the documentation of PendingIntent
for more details.

Any previously registered requests that have the same PendingIntent (as defined by
equals(Object)) will be replaced by this request.

Parameters

request

request specifying the desired data source or data type, as well as the desired
parameters for the add request