Sprawdzanie dostępności funkcji
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Gdy do Health Connect dodawane są nowe funkcje, użytkownicy nie zawsze aktualizują swoją wersję Health Connect. Interfejs Feature Availability API umożliwia sprawdzenie, czy funkcja Health Connect jest dostępna na urządzeniu użytkownika, i podjęcie odpowiednich działań.
Rozpocznij
Interfejs Feature Availability API ma takie same zależności jak pakiet SDK Health Connect. Na początek sprawdź, czy w pliku 1.1.0-alpha08
znajduje się co najmniej wersja build.gradle
:
dependencies {
implementation("androidx.health.connect:connect-client:1.1.0-alpha08")
}
Główną funkcją sprawdzania dostępności funkcji jest getFeatureStatus()
.
Zwraca stałe całkowite FEATURE_STATUS_AVAILABLE
lub 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
...
}
Listę wszystkich dostępnych flag funkcji znajdziesz na stronie referencyjnej HealthConnectFeatures
.
Obsługa braku dostępności funkcji
Jeśli jakaś funkcja nie jest dostępna na urządzeniu użytkownika, aktualizacja może ją włączyć. Możesz poprosić użytkownika o zaktualizowanie Health Connect, jeśli na jego urządzeniu nie ma najnowszej obsługiwanej wersji. Użytkownicy korzystający z pliku APK (na Androidzie 13 i starszym) nie mogą jednak używać funkcji modułu systemowego, które są dostępne tylko na urządzeniach z Androidem 14 lub nowszym.
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-23 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-08-23 UTC."],[],[],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."]]