Android APIs
public static class

DataReadRequest.Builder

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

Class Overview

Builder used to create new DataReadRequests.

Summary

Public Constructors
DataReadRequest.Builder()
Public Methods
DataReadRequest.Builder addAggregatedDataSource(DataSource dataSource)
Adds a specific data source we want aggregate data from to this request.
DataReadRequest.Builder addAggregatedDefaultDataSource(DataType dataType)
Adds the default data source for the given aggregate dataType to this request.
DataReadRequest.Builder addDataSource(DataSource dataSource)
Adds a specific data source we want data from to this request.
DataReadRequest.Builder addDefaultDataSource(DataType dataType)
Adds the default data source for the given dataType to this request.
DataReadRequest.Builder bucketByActivitySegment(int minDuration, TimeUnit timeUnit)
Specifies bucket type as TYPE_ACTIVITY_SEGMENT, sets the minimum duration of each 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 ACTIVITY_SEGMENT for computing the buckets.
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 setActivityDataSource(DataSource activityDataSource)
Sets the activity data source to be used to extract activity segments for bucketing by activity type or activity segment.
DataReadRequest.Builder setTimeRange(long startTimeMillis, long endTimeMillis)
Sets the time range for our query.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public DataReadRequest.Builder ()

Public Methods

public DataReadRequest.Builder addAggregatedDataSource (DataSource dataSource)

Adds a specific data source we want aggregate data from to this request. 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
Throws
IllegalStateException if the data source is already requested as detailed
NullPointerException if the data source is null

public DataReadRequest.Builder addAggregatedDefaultDataSource (DataType dataType)

Adds the default data source for the given aggregate 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. 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 addAggregatedDataSource(DataSource) when the application is not interested in a specific data source.

Parameters
dataType the aggregate data type we're reading
Throws
IllegalStateException if the data type is already requested as detailed
NullPointerException if the data type is null

public DataReadRequest.Builder addDataSource (DataSource dataSource)

Adds a specific data source we want 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 addDefaultDataSource (DataType dataType)

Adds the default data source 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 addDataSource(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 bucketByActivitySegment (int minDuration, TimeUnit timeUnit)

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

An 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.

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 setActivityDataSource(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)

Specifies bucket type as TYPE_ACTIVITY_TYPE, sets the minimum duration of each 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.

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 setActivityDataSource(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 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 setActivityDataSource (DataSource activityDataSource)

Sets the activity data source to be used to extract activity segments for bucketing by activity type or activity segment. If not set, the default data source for type ACTIVITY_SEGMENT is used.

Throws
IllegalArgumentException if the specified data source is invalid.

public DataReadRequest.Builder setTimeRange (long startTimeMillis, long endTimeMillis)

Sets the time range for our query. A defined start and end time is required for every read query.

Parameters
startTimeMillis a start time, in milliseconds since epoch, inclusive
endTimeMillis an end time, in milliseconds since epoch, inclusive