DataReadRequest.Builder | Android Developers

Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

Language
close

- - About
  - Wear
  - TV
  - Auto
- - Get Started
  - Devices
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
  - Google Services
  - Samples
- - Google Play
  - Essentials
  - Get Users
  - Engage & Retain
  - Monetize
  - Analyze
  - Tools & Reference
  - Developer Stories

## Results

Loading...
Summary: Ctors | Methods | Inherited Methods | [Expand All]
public static class

# DataReadRequest.Builder

extends Object

java.lang.Object
↳ | com.google.android.gms.fitness.request.DataReadRequest.Builder

## Class Overview

Builder used to create new DataReadRequests.

## Summary

Public Constructors
| DataReadRequest.Builder()

Public Methods
DataReadRequest.Builder | aggregate(DataType inputDataType, DataType outputDataType) Adds the default data source for the given aggregate `dataType` to this request and sets the output aggregate data type to be returned.
DataReadRequest.Builder | aggregate(DataSource dataSource, DataType outputDataType) Adds a specific data source we want aggregate data from for this request and also sets the output aggregate data type that will be returned.
DataReadRequest.Builder | bucketByActivitySegment(int minDuration, TimeUnit timeUnit) Specifies bucket type as `TYPE_ACTIVITY_SEGMENT`, sets the minimum duration of each `TYPE_ACTIVITY_SEGMENT` for the bucket.
DataReadRequest.Builder | bucketByActivitySegment(int minDuration, TimeUnit timeUnit, DataSource activityDataSource) Specifies bucket type as `TYPE_ACTIVITY_SEGMENT`, sets the minimum duration of each `TYPE_ACTIVITY_SEGMENT` for the bucket.
DataReadRequest.Builder | bucketByActivityType(int minDuration, TimeUnit timeUnit) Specifies bucket type as `TYPE_ACTIVITY_TYPE`, sets the minimum duration of each `TYPE_ACTIVITY_SEGMENT` for computing the buckets.
DataReadRequest.Builder | bucketByActivityType(int minDuration, TimeUnit timeUnit, DataSource activityDataSource) Specifies bucket type as `TYPE_ACTIVITY_TYPE`, sets the minimum duration of each `TYPE_ACTIVITY_SEGMENT` for computing the buckets and sets the activity data source to be used to read activity segments from.
DataReadRequest.Builder | bucketBySession(int minDuration, TimeUnit timeUnit) Specifies bucket type as `TYPE_SESSION` and sets the minimum duration of each `Session` for the bucket.
DataReadRequest.Builder | bucketByTime(int duration, TimeUnit timeUnit) Specifies bucket type as `TYPE_TIME` and sets the duration of each bucket.
DataReadRequest | build() Finishes building and returns the request.
DataReadRequest.Builder | enableServerQueries() Enable querying the Google Fit server to fetch query results, in case the local store doesn't have data for the full requested time range.
DataReadRequest.Builder | read(DataType dataType) Adds the default data source to read for the given `dataType` to this request.
DataReadRequest.Builder | read(DataSource dataSource) Adds a specific data source we want to read data from to this request.
DataReadRequest.Builder | setLimit(int limit) Limits results to the latest `limit` data points.
DataReadRequest.Builder | setTimeRange(long start, long end, TimeUnit timeUnit) Sets the time range for our query.

[Expand] Inherited Methods
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)

## Public Constructors

#### public DataReadRequest.Builder ()

## Public Methods

#### public DataReadRequest.Builder aggregate (DataType inputDataType, DataType outputDataType)

Adds the default data source for the given aggregate `dataType` to this request and sets the output aggregate data type to be returned. For a list of valid output aggregate data types for a given input data type see `getAggregatesForInput(DataType)`.

The default data source is selected based on all available sources for the given data type, and may be averaged or filtered. Aggregation should be requested in conjunction with one of the bucketing strategy: by time, session or activity. At least one valid detailed data source or aggregate data source should be specified in the request

This method can be used instead of `aggregate(DataSource, DataType)` when the application is not interested in a specific data source.

##### Parameters

inputDataType | the input data type we're aggregating
outputDataType | the output data type that will be returned

##### Throws

IllegalStateException | if the data type is already requested as detailed
IllegalArgumentException | if the input data type is not supported for aggregation or if the output data type is invalid
NullPointerException | if the data type is null

#### public DataReadRequest.Builder aggregate (DataSource dataSource, DataType outputDataType)

Adds a specific data source we want aggregate data from for this request and also sets the output aggregate data type that will be returned. For a list of valid output aggregate data types for a given input data type see `getAggregatesForInput(DataType)`.

Aggregation should be requested in conjunction with one of the bucketing strategy: by time, session or activity. At least one valid detailed data source or aggregate data source should be specified in the request.

##### Parameters

dataSource | the data source we're reading for aggregate data
outputDataType | the output data type that will be returned in the result

##### Throws

IllegalStateException | if the data source is already requested as detailed
IllegalArgumentException | if the input data type is not supported for aggregation or if the output aggregate data type is invalid
NullPointerException | if the data source is null

#### public DataReadRequest.Builder bucketByActivitySegment (int minDuration, TimeUnit timeUnit)

Specifies bucket type as `TYPE_ACTIVITY_SEGMENT`, sets the minimum duration of each `TYPE_ACTIVITY_SEGMENT` for the bucket.

An `TYPE_ACTIVITY_SEGMENT` represents a continuous time interval with a single activity value. In this case, each `Bucket` will represent an individual activity segment which lies inside the time interval of the request. For instance, if the user had two separate activity segments for walking, one for 1km and another for 2km, the result will be two buckets one with distance value of 1km and another with distance value of 2km.

If no activity segments exist recorded for specific time intervals of the read query, a Bucket corresponding to activity type `UNKNOWN` will be used instead. For instance, if there is an activity segment for biking from time [20, 30] seconds and for running from time [40, 50] seconds, the result for a read query over [0, 60] will have the following buckets:

- Bucket 1 Time Interval: [0, 20] Activity: UNKNOWN
- Bucket 2 Time Interval: [20, 30] Activity: BIKING
- Bucket 3 Time Interval: [30, 40] Activity: UNKNOWN
- Bucket 4 Time Interval: [40, 50] Activity: RUNNING
- Bucket 5 Time Interval: [50, 60] Activity: UNKNOWN

Only activity segments of duration longer than `minDuration` are chosen for bucketing.

By default, activity segments are chosen from the default data source. To use a specific data source, use `bucketByActivitySegment(int, TimeUnit, DataSource)`.

Detailed data of the aggregate type(s) specified in the request over time interval of each bucket will be aggregated and returned. Each bucket will have one `DataSet` of aggregated data for each requested aggregate `DataType`.

##### Throws

IllegalArgumentException | if another bucket type is already specified in the request or if an invalid minDuration is specified

#### public DataReadRequest.Builder bucketByActivitySegment (int minDuration, TimeUnit timeUnit, DataSource activityDataSource)

Specifies bucket type as `TYPE_ACTIVITY_SEGMENT`, sets the minimum duration of each `TYPE_ACTIVITY_SEGMENT` for the bucket.

An `TYPE_ACTIVITY_SEGMENT` represents a continuous time interval with a single activity value. In this case, each `Bucket` will represent an individual activity segment which lies inside the time interval of the request. For instance, if the user had two separate activity segments for walking, one for 1km and another for 2km, the result will be two buckets one with distance value of 1km and another with distance value of 2km.

If no activity segments exist recorded for specific time intervals of the read query, a Bucket corresponding to activity type `UNKNOWN` will be added for each missing interval. For instance, if there is an activity segment for biking from time [20, 30] seconds and for running from time [40, 50] seconds, the result for a read query over [0, 60] will have the following buckets:

- Bucket 1 Time Interval: [0, 20] Activity: UNKNOWN
- Bucket 2 Time Interval: [20, 30] Activity: BIKING
- Bucket 3 Time Interval: [30, 40] Activity: UNKNOWN
- Bucket 4 Time Interval: [40, 50] Activity: RUNNING
- Bucket 5 Time Interval: [50, 60] Activity: UNKNOWN

Only activity segments of duration longer than `minDuration` are chosen for bucketing.

The activity segments are chosen from the specified `activityDataSource`. To use the default activity data source, use `bucketByActivitySegment(int, TimeUnit)`.

Detailed data of the aggregate type(s) specified in the request over time interval of each bucket will be aggregated and returned. Each bucket will have one `DataSet` of aggregated data for each requested aggregate `DataType`.

##### Throws

IllegalArgumentException | if another bucket type is already specified in the request or if an invalid minDuration is specified

#### public DataReadRequest.Builder bucketByActivityType (int minDuration, TimeUnit timeUnit)

Specifies bucket type as `TYPE_ACTIVITY_TYPE`, sets the minimum duration of each `TYPE_ACTIVITY_SEGMENT` for computing the buckets.

In this case, each `Bucket` will represent an activity type, and be comprised of aggregated data over all individual activity segments of this activity which lie inside the time interval of the request. For instance, if the user had two separate activity segments of walking during the time interval, one for a distance of 1km and another for a distance of 2km, the result will be one activity bucket with a single aggregate data point for distance with a value of 3km.

If no activity segments are recorded for specific time intervals of the read query, segments of type `UNKNOWN` will be added for these intervals and used to compute an aggregate bucket of activity type Unknown.

Only activity segments of duration longer than `minDuration` are chosen for bucketing.

By default, activity segments are chosen from the default data source. To use a specific data source, use `bucketByActivitySegment(int, TimeUnit, DataSource)`.

Detailed data of the aggregate type(s) specified in the request over time interval of each bucket will be aggregated and returned. Each bucket will have one `DataSet` of aggregated data for each requested aggregate `DataType`.

##### Throws

IllegalArgumentException | if another bucket type is already specified in the request or if an invalid minDuration is specified.

#### public DataReadRequest.Builder bucketByActivityType (int minDuration, TimeUnit timeUnit, DataSource activityDataSource)

Specifies bucket type as `TYPE_ACTIVITY_TYPE`, sets the minimum duration of each `TYPE_ACTIVITY_SEGMENT` for computing the buckets and sets the activity data source to be used to read activity segments from.

In this case, each `Bucket` will represent an activity type, and be comprised of aggregated data over all individual activity segments of this activity which lie inside the time interval of the request. For instance, if the user had two separate activity segments of walking during the time interval, one for a distance of 1km and another for a distance of 2km, the result will be one activity bucket with a single aggregate data point for distance with a value of 3km.

If no activity segments are recorded for specific time intervals of the read query, segments of type `UNKNOWN` will be added for these intervals and used to compute an aggregate bucket of activity type Unknown.

Only activity segments of duration longer than `minDuration` are chosen for bucketing.

The activity segments are chosen from the specified `activityDataSource`. To use the default activity segment data source use `bucketByActivityType(int, TimeUnit)`.

Detailed data of the aggregate type(s) specified in the request over time interval of each bucket will be aggregated and returned. Each bucket will have one `DataSet` of aggregated data for each requested aggregate `DataType`.

##### Throws

IllegalArgumentException | if another bucket type is already specified in the request or if an invalid minDuration is specified or if an invalid activity data source is specified.

#### public DataReadRequest.Builder bucketBySession (int minDuration, TimeUnit timeUnit)

Specifies bucket type as `TYPE_SESSION` and sets the minimum duration of each `Session` for the bucket.

A `Session` represents a time interval with associate meta data to store user-visible groups of related data. In this case, each bucket will signify a session which lies inside the time interval of the request.

Detailed data of the aggregate type(s) specified in the request over time interval of each bucket will be aggregated and returned. Each bucket will have one `DataSet` of aggregated data for each requested aggregate `DataType`..

##### Throws

IllegalArgumentException | if another bucket type is already specified in the request or if an invalid minDuration is specified

#### public DataReadRequest.Builder bucketByTime (int duration, TimeUnit timeUnit)

Specifies bucket type as `TYPE_TIME` and sets the duration of each bucket.

The detailed data from the Google Fit store across the time interval of the request is divided into sub-intervals of length `duration`, and aggregation is then performed over each sub-interval to return one `Bucket` of aggregated data per sub-interval.

Aggregation is performed for data type(s) specified in the request. Each bucket will have one `DataSet` of aggregated data per requested aggregate `DataType`.

##### Throws

IllegalArgumentException | if another bucket type is already specified in the request or if an invalid duration is specified.

#### public DataReadRequest build ()

Finishes building and returns the request.

##### Throws

IllegalStateException | if the builder doesn't have enough state to create a valid request

#### public DataReadRequest.Builder enableServerQueries ()

Enable querying the Google Fit server to fetch query results, in case the local store doesn't have data for the full requested time range. Server results will be combined with local results into one DataSet.

Note that querying the server adds latency, specially under poor network conditions. Also note that attempting to query the server when there is no network connection may result in a transient error. Server queries are off by default.

#### public DataReadRequest.Builder read (DataType dataType)

Adds the default data source to read for the given `dataType` to this request. The default data source is selected based on all available sources for the given data type, and may be averaged or filtered. At least one valid detailed data source or aggregate data source should be specified in the request.

This method can be used instead of `read(DataSource)` when the application is not interested in a specific data source.

##### Parameters

dataType | the data type we're reading

##### Throws

IllegalStateException | if the data type is already requested as aggregate
NullPointerException | if the data type is null

#### public DataReadRequest.Builder read (DataSource dataSource)

Adds a specific data source we want to read data from to this request. At least one valid detailed data source or aggregate data source should be specified in the request.

##### Parameters

dataSource | the data source we're reading

##### Throws

IllegalArgumentException | if the data source is already requested as aggregate
NullPointerException | if the data source is null

#### public DataReadRequest.Builder setLimit (int limit)

Limits results to the latest `limit` data points. This parameter is ignored for aggregated queries. By default there is no limit.

This method is useful to reduce the amount of sent data as well as to support scenarios like requesting the current (limit == 1 to get the latest value) weight or height.

#### public DataReadRequest.Builder setTimeRange (long start, long end, TimeUnit timeUnit)

Sets the time range for our query. Defined start and end times are required for every read query.

##### Parameters

start | a start time, in the given unit since epoch, inclusive
end | an end time, in the given unit since epoch, inclusive
timeUnit | the unit of the start and end timestamps