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

# SessionReadRequest.Builder

extends Object

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

## Class Overview

Builder used to create a new SessionReadRequest.

## Summary

Public Constructors
| SessionReadRequest.Builder()

Public Methods
SessionReadRequest | build() Finishes building and returns the request.
SessionReadRequest.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.
SessionReadRequest.Builder | excludePackage(String appPackageName) Exclude sessions from a particular package name from the read result.
SessionReadRequest.Builder | read(DataType dataType) Reads data from the default data source of the given `dataType` for each session selected by this request.
SessionReadRequest.Builder | read(DataSource dataSource) Reads data from a given `dataSource` for each session selected by this request.
SessionReadRequest.Builder | readSessionsFromAllApps() Enables reading sessions inserted by any app.
SessionReadRequest.Builder | setSessionId(String sessionId) Adds an optional session identifier to this request.
SessionReadRequest.Builder | setSessionName(String sessionName) Adds an optional session name to this request.
SessionReadRequest.Builder | setTimeInterval(long startTime, long endTime, TimeUnit timeUnit) Sets the time range for the sessions we want to select in our query, in a specific `TimeUnit`.

[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 SessionReadRequest.Builder ()

## Public Methods

#### public SessionReadRequest build ()

Finishes building and returns the request.

##### Throws

IllegalArgumentException | if the builder doesn't have valid time interval data to create a read request
IllegalStateException | if the builder doesn't have valid data type or data source to create a read request

#### public SessionReadRequest.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.

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 SessionReadRequest.Builder excludePackage (String appPackageName)

Exclude sessions from a particular package name from the read result. This method can be used in combination with `readSessionsFromAllApps()` to exclude sessions from apps that are not of interest (for instance, sessions you have written yourself).

The method can be called multiple times to exclude more than one package from the request.

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

Reads data from the default data source of the given `dataType` for each session selected by this request. The default data source may be aggregated or merged. The read data will be returned as a separate `DataSet` for each returned session.

The data returned from the data type does not need to be inserted together with the session. The only requirement is that its timestamp fall within the session interval.

This method can be called multiple times to read multiple data types in the request.

##### Parameters

dataType | the data type we are reading

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

Reads data from a given `dataSource` for each session selected by this request. The read data will be returned as a separate `DataSet` for each returned session.

The data returned from this data source does not need to be inserted together with the session. The only requirement is that its timestamp fall within the session interval.

This method can be called multiple times to read multiple data sources in the request.

##### Parameters

dataSource | the data source we're reading

#### public SessionReadRequest.Builder readSessionsFromAllApps ()

Enables reading sessions inserted by any app. If not set, only sessions added by the calling app will be returned.

#### public SessionReadRequest.Builder setSessionId (String sessionId)

Adds an optional session identifier to this request. If specified, only the session with the exact identifier is selected.

Only one session identifier can be specified per request. Calling this method multiple times will override the previous call.

##### Parameters

sessionId | the ID of the session we want data for

#### public SessionReadRequest.Builder setSessionName (String sessionName)

Adds an optional session name to this request. If specified, only sessions with the exact name are selected.

Only one session name can be specified per request. Calling this method multiple times will override the previous call.

##### Parameters

sessionName | the name of the session we want data for

#### public SessionReadRequest.Builder setTimeInterval (long startTime, long endTime, TimeUnit timeUnit)

Sets the time range for the sessions we want to select in our query, in a specific `TimeUnit`.

Defined start and end times are required for every read query. All sessions that fall in the specified time interval are returned. Session name and identifier can be used to further restrict the returned sessions.

For a session to be returned, it has to fall completely within the interval specified in the query. Overlapping sessions with start and/or end times outside the interval will not be returned. Ongoing sessions (with no end time specified yet) whose start time falls within the interval are returned.

##### Parameters

startTime | a start time since epoch, inclusive
endTime | an end time since epoch, inclusive
timeUnit | time unit for the start and end times