Android 適用的 Google Fit API 屬於 Google Play 服務的一部分。Android 4.1 (API 級別 16) 以上版本支援 Google Fit API。應用程式可運用這些 API 執行以下操作:
讀取近乎即時的歷史資料,包括藍牙低功耗 (BLE) 裝置提供的資料。
記錄活動。
為資料與工作階段建立關聯。
設定健身目標。
讀取感應器資料
如果應用程式提供使用者活動的相關資訊 (例如每日步數),顯示使用者移動的近乎即時資料可能會很有幫助。感應器 API 可讓您存取包含此資訊的原始資料串流。這類資料可能來自 Android 裝置上的感應器,以及隨附裝置 (例如穿戴式裝置) 中的感應器。
記錄資料
如果應用程式需要收集、儲存及同步處理使用者實體活動相關資料,可以使用 Recording API。這個 API 會使用訂閱項目儲存健康與保健資料。您的應用程式指定要記錄的一種或多種活動類型。這樣一來,即使應用程式未執行,Google Fit 仍會在背景儲存指定類型的資料。也會在系統重新啟動時還原這些訂閱項目。
圖 1 Android 版 Google Fit。
歷來資料
如果您希望使用者能夠查看過往活動的健身資料,可以使用 History API。這個 API 可讓您存取歷史健康與保健資料,並可讓應用程式執行大量作業,例如插入、刪除及讀取資料。
工作階段
健身資料本身十分有用,但若能結合使用者活動的額外資訊,資料會更實用。Sessions API 會將健康與保健資料和部分中繼資料組合成名為「工作階段」的單位。工作階段代表使用者執行健身活動的一段時間間隔。
查看及設定目標
應用程式會顯示使用者的健身活動與所設定目標的比較結果,藉此激勵使用者。Goals API 可協助應用程式向使用者顯示他們建立的健康與健身目標。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eThe Google Fit APIs let your Android app read, record, and store fitness and wellness data from various sources, including BLE devices.\u003c/p\u003e\n"],["\u003cp\u003eApps can use the Recording API to continuously track user activity in the background, even when the app isn't actively running.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can access and manage historical fitness data, enabling users to view past activities and trends through the History API.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Fit allows data to be grouped into sessions, providing context and insights into specific user activities with the Sessions API.\u003c/p\u003e\n"],["\u003cp\u003eApps can leverage the Goals API to display and manage user fitness goals, promoting engagement and motivation.\u003c/p\u003e\n"]]],[],null,["# Android APIs\n\nThe Google Fit APIs for Android are part of [Google Play\nservices](/android/guides/overview). The Google Fit APIs are supported on\nAndroid 4.1 (API level 16) and higher. Using these APIs, your app can do the\nfollowing:\n\n- Read near-real-time and historic data, including data from Bluetooth Low Energy (BLE) devices.\n- Record activities.\n- Associate data with a session.\n- Set fitness goals.\n\nRead sensor data\n----------------\n\nIf your app provides information about a user's activity, such as their daily\nsteps, it can be helpful to show near-real-time data about the user's movements.\nThe [Sensors API](/fit/android/sensors) provides access to streams of raw data\nthat contain this information. The data can come from sensors available on the\nAndroid-powered device as well as from sensors in companion devices, such as\nwearables.\n\nRecord data\n-----------\n\nIf your app needs to gather, store, and sync data about a user's physical\nactivity, you can use the [Recording API](/fit/android/record). This API stores\nhealth and wellness data using subscriptions. Your app specifies one or more\ntypes of activities to record. Google Fit then stores data of the\nspecified types in the background even when your app isn't running. It also\nrestores these subscriptions when the system is restarted. \n**Figure 1.** Google Fit on Android.\n\nHistorical data\n---------------\n\nIf you want users to be able to view fitness data from past activities, you can\nuse the [History API](/fit/android/history). This API provides access to the\nhistorical health and wellness data and lets apps perform bulk operations, such\nas inserting, deleting, and reading data.\n\nSessions\n--------\n\nFitness data can be beneficial by itself, but the data is more useful when you\ncombine it with additional information about the user's activity. The [Sessions\nAPI](/fit/android/using-sessions) bundles health and wellness data, along with\nsome metadata, into units called *sessions*. Sessions represent a time interval\nduring which the user performs a fitness activity.\n\nView and set goals\n------------------\n\nYour app can help motivate users by showing how their fitness activity compares\nto the goals that they've set. The [Goals API](/fit/android/goals) helps your\napp show users the health and fitness goals that they've created."]]