운동 이벤트 처리
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
건강 관리 서비스는 ExerciseEvents
를 지원합니다. 이를 통해 운동 중에 이벤트가 발생하면 앱에 알리고 연결된 메타데이터를 제공합니다.
종속 항목 추가
운동 이벤트를 사용하려면 최신 버전의 건강 관리 서비스 SDK가 필요합니다.
건강 관리 서비스에 종속 항목을 추가하려면 프로젝트에 Google Maven 저장소를 추가해야 합니다. 자세한 내용은 Google의 Maven 저장소를 참고하세요.
그런 다음, 모듈 수준의 build.gradle
파일에 다음 종속 항목을 추가합니다.
Groovy
dependencies {
implementation "androidx.health:health-services-client:1.1.0-alpha05"
}
Kotlin
dependencies {
implementation("androidx.health:health-services-client:1.1.0-alpha05")
}
기능 확인
건강 관리 서비스의 모든 운동 및 데이터 유형과 마찬가지로 시작 시 기능을 확인합니다. 특히 ExerciseEvents
의 경우 ExerciseCapabilities
요청 외에 ExerciseTypeCapabilities.supportedExerciseEvents
를 사용하여 특정 운동에서 지원되는 운동 이벤트를 확인합니다.
특정 ExerciseEvent
가 지원되는지 확인한 후에는 getExerciseEventCapabilityDetails
를 사용하여 운동 이벤트의 기능도 쿼리해야 합니다.
다음 예에서는 기능을 쿼리하여 GOLF_SHOT_EVENT
가 지원되는지 확인하고 GOLF_SHOT_EVENT
가 스윙 유형 분류를 지원하는지 확인하는 방법을 보여줍니다.
fun handleCapabilities(capabilities: ExerciseCapabilities) {
val golfCapabilities = capabilities.typeToCapabilities[ExerciseType.GOLF]
val golfShotEventSupported =
golfCapabilities
?.supportedExerciseEvents
?.contains(ExerciseEventType.GOLF_SHOT_EVENT)
val golfSwingTypeClassificationSupported =
golfCapabilities
?.getExerciseEventCapabilityDetails(ExerciseEventType.GOLF_SHOT_EVENT)
?.isSwingTypeClassificationSupported ?: false
}
운동에서 운동 이벤트 요청
운동을 시작하고 운동의 일부로 운동 이벤트를 요청하려면 운동의 ExerciseConfig
를 선언하고 exerciseEventType
필드를 추가하세요.
다음 예는 GOLF
운동의 일부로 GOLF_SHOT_EVENT
를 요청합니다.
val config = ExerciseConfig(
exerciseType = ExerciseType.GOLF,
dataTypes = setOf(....),
// ...
exerciseEventTypes = setOf(ExerciseEventType.GOLF_SHOT_EVENT),
)
운동 이벤트 업데이트 등록
운동 업데이트를 수신하기 위해 앱에 있는 기존 인프라의 일부로 ExerciseEvent
업데이트를 받을 수 있습니다.
다음 예는 GolfShotEvent
업데이트 지원을 통합하는 방법을 보여줍니다.
val callback = object : ExerciseUpdateCallback {
override fun onExerciseUpdateReceived(update: ExerciseUpdate) {
...
}
// [ExerciseEvent] intended to come through with low latency and out of
// band of onExerciseUpdateReceived()
override fun onExerciseEventReceived(event: ExerciseEvent) {
when (event) {
is GolfShotEvent -> {
if (it.swingType == GolfShotSwingType.PUTT) {
println("Putt detected!")
}
}
}
}
}
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 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,["# Handle exercise events\n\nHealth Services provides support for [`ExerciseEvents`](/reference/kotlin/androidx/health/services/client/data/ExerciseEvent),\nwhich notify your app when an event has occurred during an exercise and supply associated metadata.\n\nAdd dependencies\n----------------\n\nUsing exercise events requires the latest version of the Health Services SDK.\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\nCheck capabilities\n------------------\n\nAs with all exercises and data types in Health Services, [check capabilities at\nstartup](/training/wearables/health-services/active-data#capabilites). For\n[`ExerciseEvents`](/reference/kotlin/androidx/health/services/client/data/ExerciseEvent)\nin particular, in addition to requesting `ExerciseCapabilities`,\nuse [`ExerciseTypeCapabilities.supportedExerciseEvents`](/reference/androidx/health/services/client/data/ExerciseTypeCapabilities#getSupportedExerciseEvents())\nto verify which exercise events are supported for the given exercise.\nAfter confirming the particular `ExerciseEvent` is supported,\nyou should also query the capabilities of the exercise event using\n[`getExerciseEventCapabilityDetails`](/reference/androidx/health/services/client/data/ExerciseTypeCapabilities#getExerciseEventCapabilityDetails).\n\nThe following example shows how to query capabilities to confirm the\n`GOLF_SHOT_EVENT` is supported, and then confirm that the `GOLF_SHOT_EVENT`\nsupports Swing Type Classification. \n\n fun handleCapabilities(capabilities: ExerciseCapabilities) {\n val golfCapabilities = capabilities.typeToCapabilities[ExerciseType.GOLF]\n val golfShotEventSupported =\n golfCapabilities\n ?.supportedExerciseEvents\n ?.contains(ExerciseEventType.GOLF_SHOT_EVENT)\n val golfSwingTypeClassificationSupported =\n golfCapabilities\n ?.getExerciseEventCapabilityDetails(ExerciseEventType.GOLF_SHOT_EVENT)\n ?.isSwingTypeClassificationSupported ?: false\n }\n\nRequest exercise events in an exercise\n--------------------------------------\n\nTo start the exercise and request an exercise event as part of the exercise,\n[declare the `ExerciseConfig` for the exercise](/training/wearables/health-services/active-data#start)\nand add a field for [`exerciseEventType`](/reference/androidx/health/services/client/data/ExerciseEventType).\n\nThe following example requests `GOLF_SHOT_EVENT` as part of a `GOLF` exercise: \n\n val config = ExerciseConfig(\n exerciseType = ExerciseType.GOLF,\n dataTypes = setOf(....),\n // ...\n exerciseEventTypes = setOf(ExerciseEventType.GOLF_SHOT_EVENT),\n )\n\nRegister for exercise event updates\n-----------------------------------\n\nYou can receive `ExerciseEvent` updates as part of the existing infrastructure\nyour app has for [receiving exercise updates](/training/wearables/health-services/active-data#updates).\nThe following example shows how you would incorporate support for `GolfShotEvent` updates: \n\n val callback = object : ExerciseUpdateCallback {\n override fun onExerciseUpdateReceived(update: ExerciseUpdate) {\n ...\n }\n // [ExerciseEvent] intended to come through with low latency and out of\n // band of onExerciseUpdateReceived()\n override fun onExerciseEventReceived(event: ExerciseEvent) {\n when (event) {\n is GolfShotEvent -\u003e {\n if (it.swingType == GolfShotSwingType.PUTT) {\n println(\"Putt detected!\")\n }\n }\n }\n }\n }"]]