DataSource.Builder

public static final class DataSource.Builder extends Object

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.

Public Constructor Summary

Public Method Summary

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.

Inherited Method Summary

Public Constructors

public DataSource.Builder ()

Public Methods

public DataSource build ()

Finishes building the data source and returns a DataSource object.

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.

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.

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.

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 one of the data types defined in DataType, or a custom data type

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.

public DataSource.Builder setName (String name)

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

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.

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.