com.google.android.gms.fitness.RecordingApi |
API which enables low-power, always-on background collection of sensor
data into the Google Fit store. Sensor subscriptions
are active when the
requesting app is not running, and persisted through system restarts. Collected data can be
queried using the History API
.
Unlike the Sensors API
, the Recording API does not support delivery of
live sensor events. When live data is needed (such as when the app is open in the
foreground), a listener should be added with the Sensors API. An app can have
both an active subscription and an active listener at the same time. Unlike listeners,
subscriptions don't need to be removed and re-added periodically.
The Recording API should be accessed from the Fitness
entry point. Example:
GoogleApiClient client = new GoogleApiClient.Builder(context) .addApi(Fitness.API) ... .build(); client.connect(); // Samples the user's activity once per minute. PendingResult<Status> pendingResult = Fitness.RecordingApi.subscribe( client, DataTypes.ACTIVITY_SAMPLE);Creating a subscription for a particular data type requires user permission for access to data of that type, and permissions can be revoked by the user through Google Play Services settings.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Reads all existing subscriptions for the current application to a particular data type.
| |||||||||||
Reads all existing subscriptions for the current application.
| |||||||||||
Subscribe to background collection of data from a specific source on behalf of the current
application.
| |||||||||||
Subscribe to background collection of data of a specific type on behalf of the current
application.
| |||||||||||
Unsubscribes from background data collection for the current application for a particular
data source.
| |||||||||||
Unsubscribes from background data collection for the current application for a particular
data type.
| |||||||||||
Unsubscribes from background data collection for the current application.
|
Reads all existing subscriptions for the current application to a particular data type.
client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the list operation will be delayed until the connection is complete. |
---|---|
dataType | list only subscriptions to this data type |
Reads all existing subscriptions for the current application.
client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the list operation will be delayed until the connection is complete. |
---|
Subscribe to background collection of data from a specific source on behalf of the current application.
After the subscription is successfully added, new data points in the requested data stream
are persisted to the Google Fit store, and can be queried via the
History Api
.
If after the subscription is added the data source becomes unavailable (it may be disconnected or disabled, for instance), the subscription remains active. Once the data source becomes available again, new data points (and any data points that were batched while disconnected) are inserted.
client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the subscribe operation will be delayed until the connection is complete. |
---|---|
dataSource | the data source to subscribe to.
|
Subscribe to background collection of data of a specific type on behalf of the current application.
Specifying a data type
instead of a data source
means
that the default data source will be used to serve this request. The default is based on the
data type and the available data sources. The default data source could be a combined data
source, and its data might be averaged or filtered. As new data sources for the data type
become available, the default data source might change.
After the subscription is successfully added, new data points in the requested data stream
are persisted to the Google Fit store, and can be queried via the
History Api
.
Note that not all data sources are available at all times (external devices may go
offline, for instance). If no data sources matching the subscription are currently
available, the request will succeed silently and
SUCCESS_NO_DATA_SOURCES
will be returned. Once data
sources become available, recording of data will start.
If after the subscription is added the data source becomes unavailable, the subscription remains active, and recording resumes once the data source becomes available again. Data points from the time interval when the data source was unavailable may or may not be recorded, depending on whether batching is supported.
If the requested subscription already exists, the request will be a no-op and
SUCCESS_ALREADY_SUBSCRIBED
will be returned.
client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the subscribe operation will be delayed until the connection is complete. |
---|---|
dataType | the data type to subscribe to.
|
Unsubscribes from background data collection for the current application for a particular data source. Should be called when the application no longer wishes to record data.
client | an existing GoogleApiClient. Must be connected at the time of this call. |
---|---|
dataSource | the data source to unsubscribe from |
IllegalStateException | if client is not connected |
---|
Unsubscribes from background data collection for the current application for a particular data type. Should be called when the application no longer wishes to record data.
client | an existing GoogleApiClient. Must be connected at the time of this call. |
---|---|
dataType | the data type to remove. All subscriptions to the
particular data type will be removed |
IllegalStateException | if client is not connected |
---|
Unsubscribes from background data collection for the current application. Should be called when the application no longer wishes to record data.
client | an existing GoogleApiClient. Must be connected at the time of this call. |
---|---|
subscription | the subscription to remove |
IllegalStateException | if client is not connected |
---|