The Google Fit APIs, including the Google Fit REST API, will be deprecated in 2026. As of May 1, 2024, developers cannot sign up to use these APIs.
For instructions on which API or platform to migrate to, visit the Health Connect migration guide. For a comparison of Health Connect with the Google Fit APIs and the Fitbit Web APIs, visit the Health Connect comparison guide.
Learn more about Health Connect and how to integrate with the API.
Data attribution
Stay organized with collections
Save and categorize content based on your preferences.
Page Summary
-
Every data point in Google Fit has an associated data source that identifies the app or device collecting the data.
-
Google Fit allows you to invoke intents to view data associated with a specific app.
-
You can register your app to receive intents from other health and wellness apps by declaring an intent filter in your manifest.
-
You can determine which app inserted a data point by getting the data source and calling its
getAppPackageNamemethod.
Every data point in Google Fit has an associated data source. Data sources contain information that identifies 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 lets you do the following:
- Invoke an intent to view data that's associated with a specific app.
- Receive intents to show data using your app.
- Find out which app inserted a session. For more information, see Work with sessions.
Determine which app inserted a data point
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:
Kotlin
valdataPoint:DataPoint=... valdataSource=dataPoint.originalDataSource valappPkgName=dataSource.appPackageName
Java
DataPointdataPoint=... DataSourcedataSource=dataPoint.getOriginalDataSource(); StringappPkgName=dataSource.getAppPackageName();
Receive intents from other apps
To register your app to receive intents from other health and wellness apps, declare an intent filter in your manifest that's similar to the following:
<intent-filter> <actionandroid:name="vnd.google.fitness.VIEW"/> <dataandroid:mimeType="vnd.google.fitness.data_type/com.google.step_count.cumulative"/> <dataandroid:mimeType="vnd.google.fitness.data_type/com.google.step_count.delta"/> </intent-filter>
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. Your app's intent filter needs to include all of the data types that your app supports, including custom data types.
The fitness intents include the following extras:
vnd.google.gms.fitness.start_timevnd.google.gms.fitness.end_timevnd.google.gms.fitness.data_source
You can obtain data from these extras as follows:
Kotlin
overridefunonCreate(savedInstanceState:Bundle?){ super.onCreate(savedInstanceState) ... valsupportedType=DataType.getMimeType(DataType.TYPE_STEP_COUNT_DELTA) if(Intent.ACTION_VIEW==intent.action && supportedType==intent.type){ // Get the intent extras valstartTime=Fitness.getStartTime(intent,TimeUnit.MILLISECONDS); valendTime=Fitness.getEndTime(intent,TimeUnit.MILLISECONDS) valdataSource=DataSource.extract(intent) } }
Java
@Override publicvoidonCreate(@NullableBundlesavedInstanceState){ super.onCreate(savedInstanceState); ... StringsupportedType=DataType.getMimeType(DataType.TYPE_STEP_COUNT_DELTA); if(Intent.ACTION_VIEW.equals(getIntent().getAction()) && supportedType.equals(getIntent().getType()) { // Get the intent extras longstartTime=Fitness.getStartTime(getIntent(),TimeUnit.MILLISECONDS); longendTime=Fitness.getEndTime(getIntent(),TimeUnit.MILLISECONDS); DataSourcedataSource=DataSource.extract(getIntent()); } }
To obtain the MIME type for a custom data type, use the
MIME_TYPE_PREFIX
constant:
Kotlin
valsupportedType=DataType.MIME_TYPE_PREFIX+"com.company.customdatatype"
Java
StringsupportedType=DataType.MIME_TYPE_PREFIX+"com.company.customdatatype";
Invoke an intent to view data
To invoke an intent to view data with another app, use the
HistoryApi.ViewIntentBuilder
class:
Kotlin
// Inside your activity valstartTime=... valendTime=... valdataSource=... valdataType=... valfitIntent=HistoryApi.ViewIntentBuilder(this,dataType) .setTimeInterval(startTime,endTime,TimeUnit.MILLISECONDS) .setDataSource(dataSource)// Optional if a specific data source is desired .setPreferredApplication("com.example.app")// Optional if you'd like a // specific app to handle the intent if that app is installed on the device .build()
Java
// Inside your activity longstartTime=... longendTime=... DataSourcedataSource=... DataTypedataType=... IntentfitIntent=newHistoryApi.ViewIntentBuilder(this,dataType) .setTimeInterval(startTime,endTime,TimeUnit.MILLISECONDS) .setDataSource(dataSource)// Optional if a specific data source is desired .setPreferredApplication("com.example.app")// Optional if you'd like a // specific app to handle the intent if that app is installed on the device .build();
Learn more about how to use intents and intent filters.