DataReadRequest

public class DataReadRequest extends Object
implements Parcelable

Request for reading data from Google Fit. Use this request to specify the data types to read, as well as aggregation parameters. Read requests require a time range and allow reading data in detailed or aggregated fashion. A single request can be used to read multiple data types and data sources together.

Detailed Data

For requesting detailed data, the request should specify:
  • the time interval for the data
  • at least one data source or data type
Example usage for reading steps during an interval:
     new DataReadRequest.Builder()
         .setTimeRange(startTime.getMillis(), endTime.getMillis(). TimeUnit.MILLISECONDS)
         .read(DataType.TYPE_STEP_COUNT_DELTA)
         .build();
 

Aggregated Data

For requesting aggregate data, the request should specify a valid bucketing strategy. Apps can request to bucket by time, activity type, activity segment, or session. Apps should also specify at least one input data source or data type to aggregate. See DataType.getAggregateType() for a list of valid input data types supported for aggregation.

The aggregation request should specify:

  • time interval for the data
  • at least one input data source or data type to aggregate and its corresponding output aggregate data type
  • bucketing strategy for aggregation

Example usage for selecting steps for each hour:

     new DataReadRequest.Builder()
          .setTimeRange(startTime.getMillis(), endTime.getMillis(), TimeUnit.MILLISECONDS)
          .bucketByTime(1, TimeUnit.HOURS)
          .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
          .build();
 

Nested Class Summary

class DataReadRequest.Builder Builder used to create new DataReadRequests. 

Constant Summary

int NO_LIMIT Constant specifying no limit has been set.

Inherited Constant Summary

Field Summary

public static final Creator<DataReadRequest> CREATOR

Public Method Summary

boolean
DataSource
getActivityDataSource()
Returns the data source used to get activity segments for creating buckets for data aggregation in this request.
List<DataSource>
getAggregatedDataSources()
Returns all of the data sources that will be read then aggregated as part of this request.
List<DataType>
getAggregatedDataTypes()
Returns all of the data types that will be read then aggregated as part of this request.
long
getBucketDuration(TimeUnit timeUnit)
Returns the bucket duration for this request in the given time unit.
int
getBucketType()
Returns the bucket type for data aggregation for this request.
List<DataSource>
getDataSources()
Returns the data sources that should be read in this request.
List<DataType>
getDataTypes()
Returns the data types for which default data sources should be read in this request.
long
getEndTime(TimeUnit timeUnit)
Returns the end time for our query, in the specified time unit
int
getLimit()
Returns the max number of data points to return in the result.
long
getStartTime(TimeUnit timeUnit)
Returns the start time for our query, in the specified time unit
int
String
void
writeToParcel(Parcel dest, int flags)

Inherited Method Summary

Constants

public static final int NO_LIMIT

Constant specifying no limit has been set.

Constant Value: 0

Fields

public static final Creator<DataReadRequest> CREATOR

Public Methods

public boolean equals (Object that)

public DataSource getActivityDataSource ()

Returns the data source used to get activity segments for creating buckets for data aggregation in this request.

This data source is used when bucketing by activity segment or activity type.

Returns
  • The data source, or null if unset.

public List<DataSource> getAggregatedDataSources ()

Returns all of the data sources that will be read then aggregated as part of this request. Each data source will be read then aggregated as specified in DataReadRequest.Builder.aggregate(DataSource).

Returns
  • The input data sources for aggregation, empty if none.

public List<DataType> getAggregatedDataTypes ()

Returns all of the data types that will be read then aggregated as part of this request. The default data source for each data type will be read, then aggregated as specified in DataReadRequest.Builder.aggregate(DataType).

Returns
  • The input data types for aggregation, empty if none.

public long getBucketDuration (TimeUnit timeUnit)

Returns the bucket duration for this request in the given time unit.

public int getBucketType ()

Returns the bucket type for data aggregation for this request.

public List<DataSource> getDataSources ()

Returns the data sources that should be read in this request.

Returns
  • All specified data sources, empty if none.

public List<DataType> getDataTypes ()

Returns the data types for which default data sources should be read in this request.

Returns
  • All specified data types, empty if none.

public long getEndTime (TimeUnit timeUnit)

Returns the end time for our query, in the specified time unit

public int getLimit ()

Returns the max number of data points to return in the result. If specified, only the latest data points up to the given limit will be read.

Returns

public long getStartTime (TimeUnit timeUnit)

Returns the start time for our query, in the specified time unit

public int hashCode ()

public String toString ()

public void writeToParcel (Parcel dest, int flags)