Wear OS 的健康照護服務
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Wear OS 3 以上版本提供「健康照護服務」。健康照護服務是裝置上各種感應器和相關演算法的中介平台,為應用程式提供與活動、運動和健康相關的高品質資料。
如需健身應用程式範例,請參閱 GitHub 上的健康照護服務範例存放區。
健康照護服務如何協助應用程式開發人員
如果沒有健康照護服務,應用程式必須連結至一或多個感應器、對每個感應器進行適當設定、接收原始感應器資料,並使用自己的演算法取得有意義的資訊。舉例來說,應用程式可以註冊 Sensor.TYPE_PRESSURE
的更新內容來取得目前的氣壓,用於計算目前的海拔高度並隨時間匯總這些資料,顯示使用者活動時段的海拔高度變化。
健康照護服務會自動根據用途妥善設定所有運動和健康相關感應器、收集感應器資料,以及計算心率、距離、卡路里、海拔高度、樓層、速度、配速等指標。應用程式可以直接從健康照護服務註冊這項資料。

使用健康照護服務的好處包括:
- 善用平台上原生執行的強大演算法。
- 使用健康照護服務中的感應器設定,對電池效能進行最佳化處理,節省電池電力。
- 保障應用程式日後可用於搭載 Wear 3 以上版本的裝置。在所有搭載 Wear 3 以上版本的裝置上,Health Services API 的功能運作均保持一致,可讓應用程式輕鬆維持最新狀態。
- 使用標準化平台運算,確保同一裝置上所有應用程式的資料一致性。
- 啟用活動感知體驗,包括偵測從其他應用程式啟動的進行中運動。
這些優勢可讓開發人員專注於開發獨特的功能和使用者體驗,同時藉助平台以節能方式提供可靠且一致的指標。
健康照護服務概念
透過健康照護服務進行開發作業時,請留意下列概念。
資料類型
健康照護服務會提供多種資料,並透過裝置所有可用來源收集並持續更新這些資料。這些資料分為兩大類別:在單一時間點取樣的資料 (例如 HEART_RATE_BPM
),以及每個時間間隔收集的資料 (例如 DISTANCE
)。
詳情請參閱資料類型的完整清單。
事件
當使用者達成特定目標狀態或事件時,應用程式會收到事件。舉例來說,使用者可以在運動應用程式中登記距離目標,然後應用程式可在使用者跑了特定距離後通知他們。或者,在使用者達成特定步數或入睡等情況下使用被動目標。
詳情請參閱「運動目標」和「被動目標」。
運動類型
健康照護服務會將運動視為優先功能,並支援多種運動類型,例如跑步或滑雪。在運動期間,健康照護服務會收集所選資料類型的指標,並回報給管理運動的應用程式。
詳情請參閱運動類型的完整清單。
使用健康照護服務建立應用程式
請按照下列各節所述,使用健康照護服務建立應用程式。
被動體驗
應用程式可以使用 PassiveMonitoringClient
實作 PassiveListenerService
,用來接收特定資料類型或事件的更新內容。這項功能適用於長期體驗,其資料更新頻率相對較低。
詳情請參閱「被動資料更新」。
使用中的體驗
應用程式可使用 MeasureClient
註冊事件監聽器,快速接收更新的資料。這項功能適用於短期體驗,例如當使用者查看應用程式 UI 時。請盡量縮短應用程式在使用已註冊事件監聽器上花費的時間,因為事件監聽器會提高感應器取樣率,從而增加耗電量。這個 API 不適用於背景擷取或健身追蹤。
詳情請參閱「使用 MeasureClient 取得即時健康測量結果」一文。
透過 ExerciseClient
,應用程式可以管理使用者的健身、設定運動目標,並監聽目前運動狀態的最新資訊。只要運動是由您的應用程式管理,應用程式也可以透過這個 API 快速接收更新的資料。ExerciseClient
可用於各種應用程式,例如跑步應用程式,可讓使用者記錄跑步情形、在裝置上顯示即時指標,以及記錄資料以供進一步分析。
詳情請參閱「使用 ExerciseClient 記錄運動情形」一文。
使用綜合資料進行測試
如要測試應用程式是否正在接收透過健康照護服務更新的資料,請手動設定裝置來發出資料,就像使用者從事運動時一樣。
詳情請參閱「搭配健康照護服務使用綜合資料」一文。
為您推薦
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# Health Services on Wear OS\n\nWear OS 3 and higher includes a service called\n[Health Services](/jetpack/androidx/releases/health).\nHealth Services acts as an intermediary to the various sensors and related\nalgorithms on the device to provide apps with high-quality data related to\nactivity, exercise, and health.\n\nSee the\n[Health Services samples repository](https://github.com/android/health-samples/tree/main/health-services)\non GitHub for example fitness apps.\n\nHow Health Services helps app developers\n----------------------------------------\n\nWithout Health Services, apps must connect to one or multiple sensors,\nconfigure each of them appropriately, receive raw sensor data, and use their\nown algorithms to derive meaningful information. For example, an app might\nregister for updates of\n[`Sensor.TYPE_PRESSURE`](/reference/kotlin/android/hardware/Sensor#type_pressure)\nto get the current air pressure, use it to compute the current altitude, and\naggregate this data over time to show the elevation changes during a user's\nactivity session.\n\nHealth Services automatically configures all fitness and health\nrelated sensors appropriately for the use-case, collects sensor data, and computes\nmetrics like heart rate, distance, calories, elevation, floors, speed, pace,\nand more. Apps can register for this data directly from Health Services.\n\nSome of the benefits of using Health Services include the following:\n\n- Takes advantage of powerful algorithms running natively on the platform.\n- Conserves battery by using sensor configurations from Health Services that are optimized for power efficiency.\n- Future-proofs an app for Wear 3+ devices. The Health Services API is consistent across Wear 3+ devices, making it easier to keep your app up to date.\n- Ensures data consistency across all applications on the same device by using standardized platform computations.\n- Enables activity-aware experiences, including the ability to detect an ongoing exercise started from another app.\n\nThese benefits let developers focus on developing unique features and user\nexperiences, while relying on the platform to provide robust and consistent\nmetrics in a power-efficient manner.\n\nHealth Services concepts\n------------------------\n\nKeep the following concepts in mind when developing with Health Services.\n\n### Data types\n\nHealth Services offers a variety of data collected and continuously updated\nfrom all the available sources on the device. The data falls into two\nbroad categories: data sampled at a single point in time, such as\n`HEART_RATE_BPM`, and data taken over a time interval, such as `DISTANCE`.\n\nFor more information, see the full list of [Data types](/reference/kotlin/androidx/health/services/client/data/DataType).\n\n### Events\n\nApps receive events when the user reaches a certain goal state or event. For\nexample, a user can register a distance goal within an exercise app, and then\nthe app notifies the user when they have run a certain distance.\nAlternatively, use a passive goal for situations like the user hitting a\ncertain step count or falling asleep.\n\nFor more information, see [Exercise goals](/reference/kotlin/androidx/health/services/client/data/ExerciseGoal) and [Passive goals](/reference/kotlin/androidx/health/services/client/data/PassiveGoal).\n\n### Exercise types\n\nHealth Services treats exercise as a first-class feature and supports a\nmultitude of exercise types, such as running or skiing. While an exercise is in\nprogress, Health Services can collect metrics on selected data types and report\nback to the app that manages the exercise.\n\nFor more information, see the full list of [exercise types](/reference/kotlin/androidx/health/services/client/data/ExerciseType).\n\nCreate apps using Health Services\n---------------------------------\n\nCreate apps using Health Services as described in the following\nsections.\n\n### Passive experiences\n\nUsing\n[`PassiveMonitoringClient`](/reference/kotlin/androidx/health/services/client/PassiveMonitoringClient),\nyour app implements a `PassiveListenerService` that receives updates about a\ndata type or an event. This is suited for long-lived experiences where data\nupdates are relatively infrequent.\n\nSee [Passive data updates](/training/wearables/health-services/passive)\nfor more information.\n\n### Active experiences\n\nUsing `MeasureClient`, your app registers listeners to receive rapid data\nupdates. This is suited for short-lived experiences, such as while the user\nlooks at your app UI. Try to minimize the time your app\nspends with a registered listener, because it increases the sensor sampling rate\nand thus increases power consumption. This API is not intended for background\ncapture or workout tracking.\n\nSee [Take spot health measurements with MeasureClient](/training/wearables/health-services/active-data/measure-client)\nfor more information.\n\nUsing `ExerciseClient`, your app can manage a user's workout, set exercise goals,\nand listen for updates about the current exercise state. Your app can also\nreceive rapid data updates through this API, as long as the exercise belongs to\nyour app. `ExerciseClient` can be used for apps such as a running app that\nlets users record their run, displays live metrics on their device, and records\ndata for further analysis.\n\nSee [Record an exercise with ExerciseClient](/training/wearables/health-services/active-data)\nfor more information.\n\n### Test with synthetic data\n\nTo test that your app is receiving data updates from Health Services, manually\nset your device to emit data as if a user were engaged in an exercise.\n\nSee [Use synthetic data with Health\nServices](/training/wearables/health-services/synthetic-data) for more information.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Record an exercise with ExerciseClient](/training/wearables/health-services/active-data)\n- [Take spot health measurements with MeasureClient](/training/wearables/health-services/active-data/measure-client)\n- [Passive data updates](/training/wearables/health-services/passive)\n- [Enhance app compatibility across Wear OS devices](/training/wearables/health-services/compatibility)"]]