檢查功能適用的國家/地區
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
「健康資料同步」新增功能時,使用者不一定會更新「健康資料同步」版本。您可以使用「功能可用性」API 檢查使用者裝置是否支援 Health Connect 功能,並決定要採取哪些動作。
開始使用
Feature Availability API 與 Health Connect SDK 共用相同的依附元件。如要開始使用,請確認 build.gradle
檔案中至少有 1.1.0-alpha08
版本:
dependencies {
implementation("androidx.health.connect:connect-client:1.1.0-alpha08")
}
檢查功能是否可用的主要函式是 getFeatureStatus()
。這會傳回整數常數 FEATURE_STATUS_AVAILABLE
或 FEATURE_STATUS_UNAVAILABLE
:
if (healthConnectClient
.features
.getFeatureStatus(
HealthConnectFeatures.FEATURE_READ_HEALTH_DATA_IN_BACKGROUND
) == HealthConnectFeatures.FEATURE_STATUS_AVAILABLE) {
// Feature is available
...
} else {
// Feature is not available
...
}
如需所有可用功能旗標的清單,請參閱 HealthConnectFeatures
參考頁面。
處理功能不適用問題
如果使用者裝置無法使用某項功能,更新後可能就能使用。如果使用者裝置上的「健康資料同步」不是最新支援版本,您可以考慮引導他們更新。不過,如果使用者透過 APK 安裝應用程式 (適用於 Android 13 以下版本),就無法使用僅適用於 Android 14 以上版本裝置的系統模組功能。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-23 (世界標準時間)。
[null,null,["上次更新時間:2025-08-23 (世界標準時間)。"],[],[],null,["# Check for feature availability\n\nWhen new features are added to Health Connect, users may not always update their\nversion of Health Connect. The Feature Availability API is a way to check if a\nfeature in Health Connect is available on your user's device and decide what\naction to take.\n\nGet started\n-----------\n\nThe Feature Availability API shares the same dependency as the Health Connect\nSDK. To get started, verify that at least version `1.1.0-alpha08` is in your\n`build.gradle` file: \n\n dependencies {\n implementation(\"androidx.health.connect:connect-client:1.1.0-alpha08\")\n }\n\nPerform the check\n-----------------\n\nThe main function to check for feature availability is `getFeatureStatus()`.\nThis returns integer constants `FEATURE_STATUS_AVAILABLE` or\n`FEATURE_STATUS_UNAVAILABLE`: \n\n if (healthConnectClient\n .features\n .getFeatureStatus(\n HealthConnectFeatures.FEATURE_READ_HEALTH_DATA_IN_BACKGROUND\n ) == HealthConnectFeatures.FEATURE_STATUS_AVAILABLE) {\n\n // Feature is available\n ...\n } else {\n // Feature is not available\n ...\n }\n\nFor a list of all available feature flags, see the [`HealthConnectFeatures`](/reference/androidx/health/connect/client/HealthConnectFeatures)\nreference page.\n\nHandle lack of feature availability\n-----------------------------------\n\nIf a feature isn't available on a user's device, an update may enable it. You\nmay consider directing the user to update Health Connect if they don't have\nthe latest supported version on their device. However, users using the APK\n(on Android 13 and lower) can't use the system module features that are only\navailable on devices running Android 14 or higher."]]