앱이 Google Fit에서 수신하는 각 인텐트는 하나의 유형만 있지만 단일 인텐트 필터에서 여러 MIME 유형을 필터링할 수 있습니다. 앱의 인텐트 필터에는 맞춤 데이터 유형을 비롯하여 앱에서 지원하는 모든 데이터 유형이 포함되어야 합니다.
피트니스 인텐트에는 다음과 같은 추가 항목이 포함됩니다.
vnd.google.gms.fitness.start_time
vnd.google.gms.fitness.end_time
vnd.google.gms.fitness.data_source
다음과 같이 이러한 추가 항목에서 데이터를 가져올 수 있습니다.
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 extrasvalstartTime=Fitness.getStartTime(intent,TimeUnit.MILLISECONDS);valendTime=Fitness.getEndTime(intent,TimeUnit.MILLISECONDS)valdataSource=DataSource.extract(intent)}}
자바
@OverridepublicvoidonCreate(@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 extraslongstartTime=Fitness.getStartTime(getIntent(),TimeUnit.MILLISECONDS);longendTime=Fitness.getEndTime(getIntent(),TimeUnit.MILLISECONDS);DataSourcedataSource=DataSource.extract(getIntent());}}
// Inside your activityvalstartTime=...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()
자바
// Inside your activitylongstartTime=...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();
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003eGoogle Fit allows developers to identify the source of fitness data, including the app or device that collected it.\u003c/p\u003e\n"],["\u003cp\u003eApps can be registered to receive intents from other health apps, enabling them to display and utilize fitness data.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can initiate intents to view specific fitness data within other apps, fostering interoperability between health platforms.\u003c/p\u003e\n"],["\u003cp\u003eData sources in Google Fit contain identifying information, including package names for apps, and are linked to individual data points.\u003c/p\u003e\n"]]],[],null,["# Data attribution\n\nEvery data point in Google Fit has an associated data source. Data sources\ncontain information that identifies the app or the device that collects or\ntransforms the data. The package name of the app is available for data sources\nthat don't represent a physical sensor.\n\nGoogle Fit lets you do the following:\n\n- Invoke an intent to view data that's associated with a specific app.\n- Receive intents to show data using your app.\n- Find out which app inserted a [session](/fit/sessions). For more information, see [Work with sessions](/fit/android/using-sessions).\n\nDetermine which app inserted a data point\n-----------------------------------------\n\nTo obtain the package name of the application that inserted a data point, first\ncall [`DataPoint.getOriginalDataSource`](/android/reference/com/google/android/gms/fitness/data/DataPoint#public-datasource-getoriginaldatasource)\nto get the data source, then call the\n[`DataSource.getAppPackageName`](/android/reference/com/google/android/gms/fitness/data/DataSource#public-string-getapppackagename)\nmethod: \n\n### Kotlin\n\n```kotlin\nval dataPoint : DataPoint = ...\nval dataSource = dataPoint.originalDataSource\nval appPkgName = dataSource.appPackageName\n```\n\n### Java\n\n```java\nDataPoint dataPoint = ...\nDataSource dataSource = dataPoint.getOriginalDataSource();\nString appPkgName = dataSource.getAppPackageName();\n```\n\nReceive intents from other apps\n-------------------------------\n\nTo register your app to receive intents from other health and wellness apps,\ndeclare an intent filter in your manifest that's similar to the following: \n\n```xml\n\u003cintent-filter\u003e\n \u003caction android:name=\"vnd.google.fitness.VIEW\" /\u003e\n \u003cdata android:mimeType=\"vnd.google.fitness.data_type/com.google.step_count.cumulative\" /\u003e\n \u003cdata android:mimeType=\"vnd.google.fitness.data_type/com.google.step_count.delta\" /\u003e\n\u003c/intent-filter\u003e\n```\n| **Note:** Don't include the `DEFAULT` category in your intent filter, unless you want your app to receive intents for data created by other apps.\n\nEach intent that your app receives from Google Fit is of only one type,\nbut you can filter for multiple MIME types in a single intent filter. Your app's\nintent filter needs to include all of the data types that your app supports,\nincluding custom data types.\n\nThe fitness intents include the following extras:\n\n- `vnd.google.gms.fitness.start_time`\n- `vnd.google.gms.fitness.end_time`\n- `vnd.google.gms.fitness.data_source`\n\nYou can obtain data from these extras as follows: \n\n### Kotlin\n\n```kotlin\noverride fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n ...\n val supportedType = DataType.getMimeType(DataType.TYPE_STEP_COUNT_DELTA)\n\n if (Intent.ACTION_VIEW == intent.action && supportedType == intent.type) {\n // Get the intent extras\n val startTime = Fitness.getStartTime(intent, TimeUnit.MILLISECONDS);\n val endTime = Fitness.getEndTime(intent, TimeUnit.MILLISECONDS)\n val dataSource = DataSource.extract(intent)\n }\n}\n```\n\n### Java\n\n```java\n@Override\npublic void onCreate(@Nullable Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n ...\n String supportedType = DataType.getMimeType(DataType.TYPE_STEP_COUNT_DELTA);\n\n if (Intent.ACTION_VIEW.equals(getIntent().getAction()) && supportedType.equals(getIntent().getType())\n {\n // Get the intent extras\n long startTime = Fitness.getStartTime(getIntent(), TimeUnit.MILLISECONDS);\n long endTime = Fitness.getEndTime(getIntent(), TimeUnit.MILLISECONDS);\n DataSource dataSource = DataSource.extract(getIntent());\n }\n}\n```\n\nTo obtain the MIME type for a custom data type, use the\n[`MIME_TYPE_PREFIX`](/android/reference/com/google/android/gms/fitness/data/DataType#public-static-final-string-mime_type_prefix)\nconstant: \n\n### Kotlin\n\n```kotlin\nval supportedType = DataType.MIME_TYPE_PREFIX + \"com.company.customdatatype\"\n```\n\n### Java\n\n```java\nString supportedType = DataType.MIME_TYPE_PREFIX + \"com.company.customdatatype\";\n```\n\nInvoke an intent to view data\n-----------------------------\n\nTo invoke an intent to view data with another app, use the\n[`HistoryApi.ViewIntentBuilder`](/android/reference/com/google/android/gms/fitness/HistoryApi.ViewIntentBuilder)\nclass: \n\n### Kotlin\n\n```kotlin\n// Inside your activity\nval startTime = ...\nval endTime = ...\nval dataSource = ...\nval dataType = ...\n\nval fitIntent = HistoryApi.ViewIntentBuilder(this, dataType)\n .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)\n .setDataSource(dataSource) // Optional if a specific data source is desired\n .setPreferredApplication(\"com.example.app\") // Optional if you'd like a\n // specific app to handle the intent if that app is installed on the device\n .build()\n```\n\n### Java\n\n```java\n// Inside your activity\nlong startTime = ...\nlong endTime = ...\nDataSource dataSource = ...\nDataType dataType = ...\n\nIntent fitIntent = new HistoryApi.ViewIntentBuilder(this, dataType)\n .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)\n .setDataSource(dataSource) // Optional if a specific data source is desired\n .setPreferredApplication(\"com.example.app\") // Optional if you'd like a\n // specific app to handle the intent if that app is installed on the device\n .build();\n```\n\nLearn more about how to use [intents and intent\nfilters](https://developer.android.com/guide/components/intents-filters)."]]