| com.google.android.gms.fitness.HistoryApi |
The Google Fit History API provides methods for inserting, deleting and reading data from the user's Google Fit history.
The readData(GoogleApiClient, DataReadRequest) method should be used whenever historical
data is needed. It can be combined with a subscription in the Recording Api
to collect data in the background and query it later for displaying.
The insert(GoogleApiClient, DataInsertRequest) method can be used for batch insertion of
data that was collected outside of Google Fit. It can be useful when data is entered directly
by the user or imported from a device that isn't supported by the platform.
The History API should be accessed via the Fitness entry point. Example:
GoogleApiClient client = new GoogleApiClient.Builder(context)
.addApi(Fitness.API)
...
.build();
client.connect();
PendingResult<DataReadResult> pendingResult = Fitness.HistoryApi.readData(
client,
new DataReadRequest.Builder()
.addDefaultDataSource(DataTypes.STEP_COUNT_DELTA)
.setTimeRange(startTime.getMillis(), endTime.getMillis())
.build());
DataReadResult readDataResult = pendingResult.await();
DataSet dataSet = readDataResult.getDataSet(DataTypes.STEP_COUNT_DELTA);
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Inserts a new data type into the user's Google Fit store on behalf of the current
application.
| |||||||||||
Deletes data and sessions from the user’s Google Fit history.
| |||||||||||
Disables Google Fit for an app.
| |||||||||||
Inserts data collected from a data source directly into the user’s Google Fit history,
on behalf of the current application.
| |||||||||||
Inserts specified
Session and corresponding data into the user's Google Fit history
on behalf of the current application. | |||||||||||
Reads data from the user’s Google Fit history.
| |||||||||||
Returns a data type with the specified dataTypeName.
| |||||||||||
Reads data from the user's Google Fit store of the specific type(s) and for the specific
session(s) selected from the request parameters.
| |||||||||||
Inserts a new data type into the user's Google Fit store on behalf of the current application. Useful for adding a custom data type for recording app specific data. Custom data created by one app will not be visible to other apps.
| client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the insertion will be delayed until the connection is complete. |
|---|---|
| request | the new data type name and fields that need to be added |
Deletes data and sessions from the user’s Google Fit history. This request will fail if the requesting app tries to delete data that it hasn't inserted. The user can delete data from any application (or hardware sensors) by visiting the Google Fit dashboard.
| client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the deletion will be delayed until the connection is complete. |
|---|---|
| request | specifying the data source/type, sessions and time range to delete |
Disables Google Fit for an app. Can be used to revoke all granted OAuth access permissions from an app and consequently remove all existing subscriptions and registrations of the app.
| client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the read result will be delayed until the connection is complete. |
|---|
Inserts data collected from a data source directly into the user’s Google Fit history, on behalf of the current application. Useful when the data source isn't compatible with our platform or when we're importing historical data.
If the data source can be exposed via a BLE GATT profile,
as an application
sensor, or some other method compatible with the platform, it's preferable to create a
subscription via the Recording API instead of inserting data directly.
| client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the insertion will be delayed until the connection is complete. |
|---|---|
| request | the data we’re adding, which includes a data set for a given data source. |
Inserts specified Session and corresponding data into the user's Google Fit history
on behalf of the current application. Useful for bulk upload of a previously recorded
Session.
| client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the insertion will be delayed until the connection is complete. |
|---|---|
| request | the Session and its associated data that we are adding, which includes
details of the session and data set for data source(s).
|
Reads data from the user’s Google Fit history. Values can be read in detailed or in aggregate formats. Aggregate data is presented in buckets, while detailed data is returned as a single data set.
| client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the read operation will be delayed until the connection is complete. |
|---|---|
| request | a built request specifying the data sources we’re interested in reading and the time range of the returned data. |
Returns a data type with the specified dataTypeName. Useful to retrieve custom data types added by an app. Custom data types created by other apps will not be returned.
| client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the read result will be delayed until the connection is complete. |
|---|---|
| dataTypeName | name of the data type we want to read |
Reads data from the user's Google Fit store of the specific type(s) and for the specific session(s) selected from the request parameters.
| client | an existing GoogleApiClient. It does not need to be connected at the time of this call, but the insertion will be delayed until the connection is complete. |
|---|---|
| request | a built request specifying the specific session or time interval and/or data type we are interested in reading. |