public interface

HistoryApi

com.google.android.gms.fitness.HistoryApi

Class Overview

API for inserting, deleting, and reading data in Google Fit.

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 insertData(GoogleApiClient, DataSet) 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()
             .read(DataTypes.STEP_COUNT_DELTA)
             .setTimeRange(startTime.getMillis(), endTime.getMillis(), TimeUnit.MILLISECONDS)
             .build());

     DataReadResult readDataResult = pendingResult.await();
     DataSet dataSet = readDataResult.getDataSet(DataTypes.STEP_COUNT_DELTA);
 

Summary

Nested Classes
class HistoryApi.ViewIntentBuilder Builder of intents to view data stored in Google Fit. 
Public Methods
abstract PendingResult<Status> deleteData(GoogleApiClient client, DataDeleteRequest request)
Deletes data from the user’s Google Fit history.
abstract PendingResult<Status> insertData(GoogleApiClient client, DataSet dataSet)
Inserts data collected from a data source directly into the user’s Google Fit history, on behalf of the current application.
abstract PendingResult<DataReadResult> readData(GoogleApiClient client, DataReadRequest request)
Reads data from the user’s Google Fit history.

Public Methods

public abstract PendingResult<Status> deleteData (GoogleApiClient client, DataDeleteRequest request)

Deletes data 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.

Parameters
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 and time range to delete
Returns
  • a pending result containing status of the request

public abstract PendingResult<Status> insertData (GoogleApiClient client, DataSet dataSet)

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 Google Fit or for importing historical data.

If the data source can be exposed via a BLE GATT profile, an application-exposed sensor, or some other method compatible with Google Fit, it's preferable to create a subscription via the Recording API instead of inserting data directly.

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.
dataSet the data we’re adding
Returns
  • a pending result containing ths status of the request

public abstract PendingResult<DataReadResult> readData (GoogleApiClient client, DataReadRequest request)

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.

Parameters
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 pending result containing the requested data. Includes a data set for each requested data source.