When new features are added to Health Connect, users may not always update their version of Health Connect. The Feature Availability API is a way to check if a feature in Health Connect is available on your user's device and decide what action to take.
Get started
The Feature Availability API shares the same dependency as the Health Connect
SDK. To get started, verify that at least version 1.1.0-alpha08
is in your
build.gradle
file:
dependencies {
implementation("androidx.health.connect:connect-client:1.1.0-alpha08")
}
Perform the check
The main function to check for feature availability is getFeatureStatus()
.
This returns integer constants FEATURE_STATUS_AVAILABLE
or
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
...
}
Handle lack of feature availability
If a feature isn't available on a user's device, an update may enable it. You may consider directing the user to update Health Connect if they don't have the latest supported version on their device. However, users using the APK (on Android 13 and lower) can't use the system module features that are only available on devices running Android 14 or higher.