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

# SensorRequest.Builder

extends Object

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

## Class Overview

Builder used to create new SensorRequests.

## Summary

Public Constructors
| SensorRequest.Builder()

Public Methods
SensorRequest | build() Finishes building and returns the request.
SensorRequest.Builder | setAccuracyMode(int accuracyMode) Sets the accuracy policy (mode) expected by the application.
SensorRequest.Builder | setDataSource(DataSource dataSource) Sets the specific data source for this registration.
SensorRequest.Builder | setDataType(DataType dataType) Sets the data type for the request.
SensorRequest.Builder | setFastestRate(int fastestInterval, TimeUnit unit) Sets the fastest interval between two consecutive data points, in the given unit.
SensorRequest.Builder | setMaxDeliveryLatency(int interval, TimeUnit unit) Sets the maximum latency between a data point being detected and reported to the application.
SensorRequest.Builder | setSamplingRate(long interval, TimeUnit unit) Sets the desired interval between two consecutive data points, in the given unit.
SensorRequest.Builder | setTimeout(long timeout, TimeUnit timeUnit) Sets the timeout for the registration for the sensor request to expire.

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

## Public Methods

#### public SensorRequest build ()

Finishes building and returns the request.

##### Throws

IllegalStateException | if the builder doesn't have enough data to build a valid request

#### public SensorRequest.Builder setAccuracyMode (int accuracyMode)

Sets the accuracy policy (mode) expected by the application. The Accuracy mode is passed along to the underlying data source. Setting this value has a direct impact in battery usage: i.e. a high accuracy can improve the quality of the data collected at the expense of higher battery consumption.

The accuracy mode is a hint to the system. If no accuracy is specified, or if the underlying data source does not support it, a balanced policy is used.

Example usage:

         builder.setAccuracyMode(SensorRequest.ACCURACY_MODE_LOW) // lowest impact in battery

##### Parameters

accuracyMode | the accuracy mode to be passed to the data sources

#### public SensorRequest.Builder setDataSource (DataSource dataSource)

Sets the specific data source for this registration. Either this method or `setDataType(DataType)` must be called to specify the data source for each request.

##### Parameters

dataSource | the data source from which we want to receive live events

#### public SensorRequest.Builder setDataType (DataType dataType)

Sets the data type for the request. This can be used instead of `setDataSource(DataSource)` to use a default data source for the request, based on the data type and the available data sources.

It's not necessary to set the data type if the data source is also set.

##### Parameters

dataType | the data type for which we want to receive live events

#### public SensorRequest.Builder setFastestRate (int fastestInterval, TimeUnit unit)

Sets the fastest interval between two consecutive data points, in the given unit. The system will not deliver data points faster than this rate, even if they're passively available from other applications. Example:

         builder.setFastestRate(5, TimeUnit.SECONDS)

If the fastest rate is unspecified, a default rate will be used. The default rate is data type specific.

##### Parameters

fastestInterval | the fastest interval between data points, in the given unit
unit | unit for the interval. Intervals can be specified in up to microsecond granularity.

#### public SensorRequest.Builder setMaxDeliveryLatency (int interval, TimeUnit unit)

Sets the maximum latency between a data point being detected and reported to the application. The max delivery latency is passed along to the underlying data source and used to enable batching. Batching can save battery by reducing the number of times the Application Processor is awaken, and the number of network transfers for external data sources.

The max latency is a hint to the system, and events can be received faster or slower than the specified interval. If no interval is specified, or if the underlying data source does not support batching, events are reported as soon as they are detected.

Example usage:

         builder.setMaxDeliveryLatency(1, TimeUnit.MINUTES) // delivery at least once a minute

##### Parameters

interval | the maximum interval between detection and reporting of events
unit | unit for the given interval. Intervals can be specified in up to microsecond granularity.

#### public SensorRequest.Builder setSamplingRate (long interval, TimeUnit unit)

Sets the desired interval between two consecutive data points, in the given unit. This is only a hint to the system. Events may be received faster or slower than the specified rate (usually faster). Example:

         builder.setSamplingRate(10, TimeUnit.SECONDS) // sample every 10 seconds

If the sampling rate is unspecified, a default rate will be used. The default rate is data type specific.

##### Parameters

interval | the desired interval between data points, in the given unit
unit | unit for the interval. Intervals can be specified in up to microsecond granularity.

#### public SensorRequest.Builder setTimeout (long timeout, TimeUnit timeUnit)

Sets the timeout for the registration for the sensor request to expire. Registration for this sensor request will automatically expire after this time and app will stop getting live sensor updates.

This timeout is intended to avoid situations where an app fails to unregister from a sensor request. If apps do not set a timeout value, a default timeout will be chosen for the sensor registration request to expire.

##### Parameters

timeout | the timeout duration after which the registration expires
timeUnit | unit for the timeout