Builder used to create a new SessionReadRequest.
Public Constructor Summary
Builder()
|
Public Method Summary
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 |
includeActivitySessions()
Requests to include activity sessions.
|
SessionReadRequest.Builder |
includeSleepSessions()
Requests to include sleep sessions.
|
SessionReadRequest.Builder |
read(DataSource
dataSource)
Reads data from a given
dataSource for each session selected by
this request.
|
SessionReadRequest.Builder | |
SessionReadRequest.Builder |
readSessionsFromAllApps()
Enables reading sessions inserted by any app.
|
SessionReadRequest.Builder | |
SessionReadRequest.Builder | |
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 .
|
Inherited Method Summary
Public Constructors
public 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 includeActivitySessions ()
Requests to include activity sessions. Activity sessions are sessions of activity
types other than FitnessActivities.SLEEP
in FitnessActivities
.
public SessionReadRequest.Builder includeSleepSessions ()
Requests to include sleep sessions. Sleep sessions are of activity type
FitnessActivities.SLEEP
.
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 you're reading. |
---|
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 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 you 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 you 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. |