Data Attribution

Every data point in Google Fit has an associated data source. Data sources contain information to identify the app or the device that collects or transforms the data. The package name of the app is available for data sources that don't represent a physical sensor.

Google Fit enables you to:

  • Determine which app inserted fitness data.
  • Fire an intent to view fitness data with a specific app.
  • Receive intents to show fitness data using your app.

For example, an app that analyzes a variety of data from the user's fitness history may want to present users with the list of fitness sessions included in the analysis, along with information about which app inserted each session. When users tap on each session, the app can fire an intent to show a detailed view of the session using a different app.

Determine which app inserted fitness data

To obtain the package name of the application that inserted a session, use the Session.getAppPackageName method:

Session session = ...;
String appPkgName = session.getAppPackageName();

To obtain the package name of the application that inserted a data point, first call DataPoint.getOriginalDataSource to get the data source, then call the DataSource.getAppPackageName method:

DataPoint dataPoint = ...;
DataSource dataSource = dataPoint.getOriginalDataSource();
String appPkgName = dataSource.getAppPackageName();

Get more information about an app

To determine whether an Android app is installed on the device and obtain more information about the app (such as its icon), use the Android PackageManager class:

// Inside your activity
try {
    PackageManager pkgManager = this.getPackageManager();
    Drawable appIcon = pkgManager.getApplicationIcon(appPkgName);
} catch (PackageManager.NameNotFoundException e) {
    // The app is not installed on this device

Receive intents from fitness apps

To register your app to receive intents from other fitness apps, declare an intent filter in your manifest like the following:

    <action android:name="" />
    <data android:mimeType="" />
    <data android:mimeType="" />

Each intent that your app receives from Google Fit is of only one type, but you can filter for multiple MIME types in a single intent filter. You should include all the data types that your app supports in your intent filter, including custom data types.

The fitness intents include all of the following extras:

  • ""
  • ""
  • ""
  • ""

You can obtain data from these extras as follows:

void onCreate (Bundle savedInstanceState) {
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    String supportedType = DataType.getMimeType(DataType.TYPE_STEP_COUNT_DELTA);

    if (Intent.ACTION_VIEW.equals(action) &&
        supportedType.compareTo(type) == 0) {

        // Get the intent extras
        long startTime = Fitness.getStartTime(intent, TimeUnit.MILLISECONDS);
        long endTime = Fitness.getEndTime(intent, TimeUnit.MILLISECONDS);
        DataSource dataSource = DataSource.extract(intent);
        Session session = Session.extract(intent);

        // Show the session in your app

To obtain the MIME type for a custom data type, use the MIME_TYPE_PREFIX constant:

String supportedType = DataType.MIME_TYPE_PREFIX + "";

Fire an intent to view fitness data

To fire an intent to view fitness data with another app, use the HistoryApi.ViewIntentBuilder class.

// Inside your activity
long startTime = ...;
long endTime = ...;
DataSource dataSource = ...;

Intent fitIntent = new HistoryApi.ViewIntentBuilder(this)
    .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
    .setPreferredApplication("") // optional

Fore more information about intents, see Intents and Intent Filters.

Send feedback about...