public static final class

DataSource.Builder

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

Class Overview

A builder that can be used to construct new data source objects. In general, a built data source should be saved in memory to avoid the cost of re-constructing it for every request.

Summary

Public Constructors
DataSource.Builder()
Public Methods
DataSource build()
Finishes building the data source and returns a DataSource object.
DataSource.Builder setAppPackageName(String packageName)
Sets the package name for the application that is recording or computing the data.
DataSource.Builder setAppPackageName(Context appContext)
Sets the package name for the application that is recording or computing the data based on the app's context.
DataSource.Builder setDataQualityStandards(int... dataQualityStandards)
Sets the list of data quality standards adhered to by this data source.
DataSource.Builder setDataType(DataType dataType)
Sets the data type for the data source.
DataSource.Builder setDevice(Device device)
Sets the integrated device where data is being recorded (for instance, a phone that has sensors, or a wearable).
DataSource.Builder setName(String name)
Sets an end-user-visible name for this data source.
DataSource.Builder setStreamName(String streamName)
The stream name uniquely identifies this particular data source among other data sources of the same type from the same underlying producer.
DataSource.Builder setType(int type)
Sets the type of the data source.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public DataSource.Builder ()

Public Methods

public DataSource build ()

Finishes building the data source and returns a DataSource object.

Returns
DataSource
Throws
IllegalStateException if the builder didn't have enough data to build a valid data source.

public DataSource.Builder setAppPackageName (String packageName)

Sets the package name for the application that is recording or computing the data. Used for data sources that aren't built into the platform (local sensors and BLE sensors are built-in). It can be used to identify the data source, to disambiguate between data from different applications, and also to link back to the original application for a detailed view.

Parameters
packageName String
Returns
DataSource.Builder

public DataSource.Builder setAppPackageName (Context appContext)

Sets the package name for the application that is recording or computing the data based on the app's context. This method should be preferred when an application is creating a data source that represents its own data. When creating a data source to query data from other apps, setAppPackageName(String) should be used.

Parameters
appContext Context
Returns
DataSource.Builder

public DataSource.Builder setDataQualityStandards (int... dataQualityStandards)

Sets the list of data quality standards adhered to by this data source.

This field is ignored by all Fit APIs. It exists so that developers may create DataSource objects for testing which will return a value from getDataQualityStandards(). In DataSource objects returned by Fit APIs, the data quality standards list is set from an internally maintained mapping.

Parameters
dataQualityStandards int
Returns
DataSource.Builder

public DataSource.Builder setDataType (DataType dataType)

Sets the data type for the data source. Every data source is required to have a data type.

Parameters
dataType DataType: one of the data types defined in DataType, or a custom data type
Returns
DataSource.Builder

public DataSource.Builder setDevice (Device device)

Sets the integrated device where data is being recorded (for instance, a phone that has sensors, or a wearable). Can be useful to identify the data source, and to disambiguate between data from different devices. If the data is coming from the local device, use Device.getLocalDevice(Context).

Note that it may be useful to set the device even if the data is not coming from a hardware sensor on the device. For instance, if the user installs an application which generates sensor data in two separate devices, the only way to differentiate the two data sources is using the device. This can be specially important if both devices are used at the same time.

Parameters
device Device
Returns
DataSource.Builder

public DataSource.Builder setName (String name)

Sets an end-user-visible name for this data source. This is optional.

Parameters
name String
Returns
DataSource.Builder

public DataSource.Builder setStreamName (String streamName)

The stream name uniquely identifies this particular data source among other data sources of the same type from the same underlying producer. Setting the stream name is optional, but should be done whenever an application exposes two streams for the same data type, or when a device has two equivalent sensors.

The stream name is used by getStreamIdentifier() to make sure the different streams are properly separated when querying or persisting data.

Parameters
streamName String
Returns
DataSource.Builder
Throws
IllegalArgumentException if the specified stream name is null

public DataSource.Builder setType (int type)

Sets the type of the data source. TYPE_DERIVED should be used if any other data source is used in generating the data. TYPE_RAW should be used if the data comes completely from outside of Google Fit.

Parameters
type int
Returns
DataSource.Builder