سيتم إيقاف واجهات برمجة تطبيقات Google Fit نهائيًا في عام 2026، بما في ذلك واجهة برمجة التطبيقات Google Fit REST API. اعتبارًا من 1 أيار (مايو) 2024، لن يتمكّن المطوّرون من الاشتراك لاستخدام واجهات برمجة التطبيقات هذه.
للحصول على تعليمات حول واجهة برمجة التطبيقات أو المنصة التي تريد نقل البيانات إليها، يُرجى الانتقال إلى دليل نقل البيانات في Health Connect. للاطّلاع على مقارنة بين Health Connect وGoogle Fit API وFitbit Web API، يُرجى الانتقال إلى دليل مقارنة Health Connect.
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
لكل نقطة بيانات في Google Fit مصدر بيانات مرتبط بها. تحتوي مصادر البيانات
على معلومات تحدِّد التطبيق أو الجهاز الذي يجمع البيانات أو
يحوّلها. يتوفّر اسم حزمة التطبيق لمصادر البيانات
التي لا تمثّل جهاز استشعار ماديًا.
فكل هدف يتلقاه تطبيقك من 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)}}
Java
@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());}}
للحصول على نوع MIME لنوع بيانات مخصّص، استخدم
MIME_TYPE_PREFIX
الثابت:
// 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()
Java
// 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();
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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)."]]