public class

ViewDataIntentBuilder

extends Object
java.lang.Object
   ↳ com.google.android.gms.fitness.ViewDataIntentBuilder

Class Overview

Builder of intents to view data stored in Google Fit, for a particular data source. This intent can be used when the application wants to display a more detailed view of a particular data type. Apps that can handle that data type (such as the app that inserted the data) can register for the intent.

If desired, setPreferredApplication(String) can be called to set a specific application to handle the intent, if the application is installed on the device. This will often be the application defined in getAppPackageName().

The data view intent has the following attributes:

  • action is set to ACTION_VIEW
  • type is MIME_TYPE_DATA_TYPE_PREFIX followed by the data type name. For example vnd.google.fitness.data_type/com.google.step_count.cumulative.
  • extras contain the data source, start time, and end time. Each of them has a corresponding constant defined in FitnessIntents.

An application that would like to handle data view intents should create an activity and add an intent filter to its manifest file. Here's an example activity that can display heart rate data:

 <activity android:name="com.example.ViewHeartRateActivity" android:exported="true">
    <intent-filter>
      <action android:name="vnd.google.fitness.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:mimeType="vnd.google.fitness.data_type/com.google.heart_rate.bpm" />
   </intent-filter>
 </activity>
 

Summary

Public Constructors
ViewDataIntentBuilder(Context context)
Public Methods
Intent build()
Returns the built intent, which can be used with startActivity(Intent) to launch the desired Fitness activity.
ViewDataIntentBuilder setDataSource(DataSource dataSource)
Sets the data source to display data for, if a specific data source is desired.
ViewDataIntentBuilder setPreferredApplication(String packageName)
Sets a preferred application to use for this intent.
ViewDataIntentBuilder setTimeInterval(long startTimeMillis, long endTimeMillis)
Sets the time interval to display data for.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ViewDataIntentBuilder (Context context)

Public Methods

public Intent build ()

Returns the built intent, which can be used with startActivity(Intent) to launch the desired Fitness activity.

Throws
IllegalStateException if not enough data has been passed into the Builder to build a valid intent.

public ViewDataIntentBuilder setDataSource (DataSource dataSource)

Sets the data source to display data for, if a specific data source is desired. Otherwise, the viewer can choose any data source or use the default one.

Parameters
dataSource the specific data source we want to display data for

public ViewDataIntentBuilder setPreferredApplication (String packageName)

Sets a preferred application to use for this intent. If the given app is installed and able to handle this intent, an explicit intent will be returned. This can be used in combination with getAppPackageName() to link back to the original application which inserted the data being displayed.

Parameters
packageName the package name for the application we want to link to
Returns
  • this builder, for chaining

public ViewDataIntentBuilder setTimeInterval (long startTimeMillis, long endTimeMillis)

Sets the time interval to display data for. Every intent requires a valid time interval.

Parameters
startTimeMillis start time, inclusive, in milliseconds since epoch
endTimeMillis end time, exclusive, in milliseconds since epoch