등록된 각 콜백은 단일 데이터 유형을 위한 것입니다. 일부 데이터 유형은 가용 상태가 다를 수 있습니다. 예를 들어, 기기가 손목에 제대로 붙어 있지 않으면 심박수 데이터가 제공되지 않을 수도 있습니다.
콜백으로 인해 센서 샘플링 레이트가 증가하고 이에 따라 전력 소모가 증가하므로 콜백이 등록되는 시간을 최소화하는 것이 중요합니다.
다음 예는 HEART_RATE_BPM 데이터를 수신하는 콜백을 등록 및 등록 취소하는 방법을 보여줍니다.
valheartRateCallback=object:MeasureCallback{overridefunonAvailabilityChanged(dataType:DeltaDataType<*,*>,availability:Availability){if(availabilityisDataTypeAvailability){// Handle availability change.}}overridefunonDataReceived(data:DataPointContainer){// Inspect data points.}}valhealthClient=HealthServices.getClient(this/*context*/)valmeasureClient=healthClient.measureClient// Register the callback.measureClient.registerMeasureCallback(DataType.Companion.HEART_RATE_BPM,heartRateCallback)// Unregister the callback.awaitClose{runBlocking{measureClient.unregisterMeasureCallbackAsync(DataType.Companion.HEART_RATE_BPM,heartRateCallback)}}
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(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-07-27(UTC)"],[],[],null,["# Take spot health measurements with MeasureClient\n\nWith the\n[`MeasureClient`](/reference/androidx/health/services/client/MeasureClient)\nAPI, your app registers callbacks to receive data for a short amount of time.\nThis is meant for situations in which your app is in use and requires rapid data\nupdates. If possible, create this with a foreground UI so that the user is\naware.\n| **Note:** `MeasureClient` is not suitable for workout tracking. Instead, [record an\n| exercise](/training/wearables/health-services/active-data/exercise-client) using `ExerciseClient`.\n\nAdd dependencies\n----------------\n\nTo add a dependency on Health Services, you must add the Google Maven repository\nto your project. For more information, see\n[Google's Maven repository](/studio/build/dependencies#google-maven).\n\nThen, in your module-level `build.gradle` file, add the following dependency: \n\n### Groovy\n\n```groovy\ndependencies {\n implementation \"androidx.health:health-services-client:1.1.0-alpha05\"\n}\n```\n\n### Kotlin\n\n```kotlin\ndependencies {\n implementation(\"androidx.health:health-services-client:1.1.0-alpha05\")\n}\n```\n| **Note:** This API is asynchronous and relies on `ListenableFuture` extensively. See [Using a ListenableFuture](/guide/background/listenablefuture) for more information about this concept.\n\nCheck capabilities\n------------------\n\nBefore registering for data updates, check that the device can provide the type\nof data your app needs. By checking capabilities first, you can enable or\ndisable certain features or modify your app's UI to compensate for capabilities\nthat are not available.\n\nThe following example shows how to check whether a device can provide the\n`HEART_RATE_BPM` data type: \n\n val healthClient = HealthServices.getClient(this /*context*/)\n val measureClient = healthClient.measureClient\n lifecycleScope.launch {\n val capabilities = measureClient.getCapabilitiesAsync().await()\n supportsHeartRate = DataType.HEART_RATE_BPM in capabilities.supportedDataTypesMeasure\n }\n\nRegister for data\n-----------------\n\n| **Note:** Request necessary permissions before registering to receive data that requires a permission.\n\nEach callback you register is for a single data type. Note that some data types\nmight have varying states of availability. For example, heart rate data might not\nbe available when the device is not properly attached to the wrist.\n\nIt's important to minimize the amount of time that your callback is registered,\nas callbacks cause an increase in sensor sampling rates, which in turn increases\npower consumption.\n\nThe following example shows how to register and unregister a callback to receive\n`HEART_RATE_BPM` data: \n\n val heartRateCallback = object : MeasureCallback {\n override fun onAvailabilityChanged(dataType: DeltaDataType\u003c*, *\u003e, availability: Availability) {\n if (availability is DataTypeAvailability) {\n // Handle availability change.\n }\n }\n\n override fun onDataReceived(data: DataPointContainer) {\n // Inspect data points.\n }\n }\n val healthClient = HealthServices.getClient(this /*context*/)\n val measureClient = healthClient.measureClient\n\n // Register the callback.\n measureClient.registerMeasureCallback(DataType.Companion.HEART_RATE_BPM, heartRateCallback)\n\n // Unregister the callback.\n awaitClose {\n runBlocking {\n measureClient.unregisterMeasureCallbackAsync(DataType.Companion.HEART_RATE_BPM, heartRateCallback)\n }\n }\n\n| **Note:** Kotlin developers can use `callbackFlow` to take advantage of coroutines and lifecycle. See the [Measure Data sample](https://github.com/android/health-samples/tree/main/health-services/MeasureDataCompose) on GitHub for an example."]]