ตรวจสอบความพร้อมใช้งานของฟีเจอร์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เมื่อมีการเพิ่มฟีเจอร์ใหม่ๆ ลงใน Health Connect ผู้ใช้อาจไม่อัปเดต Health Connect
เวอร์ชันของตนเสมอไป Feature Availability API เป็นวิธีตรวจสอบว่าฟีเจอร์ใน Health Connect พร้อมใช้งานในอุปกรณ์ของผู้ใช้หรือไม่ และตัดสินใจว่าจะดำเนินการใด
เริ่มต้นใช้งาน
Feature Availability API มีการอ้างอิงเดียวกันกับ Health Connect
SDK หากต้องการเริ่มต้นใช้งาน ให้ตรวจสอบว่าไฟล์ 1.1.0-alpha08
มีเวอร์ชันอย่างน้อย
build.gradle
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
อ้างอิง
จัดการเมื่อฟีเจอร์ไม่พร้อมใช้งาน
หากฟีเจอร์ไม่พร้อมใช้งานในอุปกรณ์ของผู้ใช้ การอัปเดตอาจทำให้ฟีเจอร์พร้อมใช้งาน คุณอาจพิจารณานำผู้ใช้ไปอัปเดต Health Connect หากผู้ใช้ไม่มี
เวอร์ชันล่าสุดที่รองรับในอุปกรณ์ อย่างไรก็ตาม ผู้ใช้ที่ใช้ APK (ใน Android 13 และต่ำกว่า) จะใช้ฟีเจอร์ของโมดูลระบบที่ใช้ได้เฉพาะในอุปกรณ์ที่ใช้ Android 14 ขึ้นไปไม่ได้
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-23 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 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."]]