android / android/health-samples
swim distance, lap count
- Dominant language
- Kotlin
- Stars
- 346
- Forks
- 183
- PR merge metrics
- No merged PRs in 30d
Description
I use implementation 'androidx.health:health-services-client:1.0.0-beta03'
----- start
val capabilities = getExerciseCapabilities(exerciseType) ?: return
val dataTypes = setOf(
DataType.HEART_RATE_BPM,
DataType.HEART_RATE_BPM_STATS,
DataType.CALORIES_TOTAL,
DataType.DISTANCE_TOTAL,
DataType.SWIMMING_STROKES_TOTAL,
DataType.SWIMMING_LAP_COUNT
).intersect(capabilities.supportedDataTypes)
val exerciseGoals = mutableListOf>()
if (supportsCalorieGoal(capabilities)) {
// Create a one-time goal.
exerciseGoals.add(
ExerciseGoal.createOneTimeGoal(
DataTypeCondition(
dataType = DataType.CALORIES_TOTAL,
threshold = CALORIES_THRESHOLD,
comparisonType = ComparisonType.GREATER_THAN_OR_EQUAL
)
)
)
}
if (supportsDistanceMilestone(capabilities)) {
// Create a milestone goal. To make a milestone for every kilometer, set the initial
// threshold to 1km and the period to 1km.
val distanceThreshold = if (args.isOpenWaterSwimType) DISTANCE_THRESHOLD
else args.poolSizeModel.poolSize.toDouble()
exerciseGoals.add(
ExerciseGoal.createMilestone(
condition = DataTypeCondition(
dataType = DataType.DISTANCE_TOTAL,
threshold = distanceThreshold, //DISTANCE_THRESHOLD,
comparisonType = ComparisonType.GREATER_THAN_OR_EQUAL
),
period = DISTANCE_PERIOD //DISTANCE_THRESHOLD
)
)
}
val poolLength = if (args.isOpenWaterSwimType) {
SWIMMING_POOL_LENGTH_UNSPECIFIED
} else max(15f, args.poolSizeModel.getPoolSizeMeters())
try {
val config = ExerciseConfig(
exerciseType = exerciseType,
dataTypes = dataTypes,
isAutoPauseAndResumeEnabled = false,
isGpsEnabled = true,
exerciseGoals = exerciseGoals,
swimmingPoolLengthMeters = poolLength
)
log(config.toString())
exerciseClient.startExerciseAsync(config).await()
} catch (e: Throwable) {
log("Start exercise failed - ${e.message}")
}
----------------- Prepare
val exerciseType = if (args.isOpenWaterSwimType) {
ExerciseType.SWIMMING_OPEN_WATER
} else ExerciseType.SWIMMING_POOL
val dataTypes = if (args.isOpenWaterSwimType) {
setOf(DataType.HEART_RATE_BPM, DataType.LOCATION)
} else setOf(DataType.HEART_RATE_BPM, DataType.DISTANCE)
val warmUpConfig = WarmUpConfig(exerciseType, dataTypes)
try {
exerciseClient.prepareExerciseAsync(warmUpConfig).await()
...
----------
after starting an exercise I never catch distance or lap count an event.
So, can you help me? How to fix it?
also ExerciseType.SWIMMING_POOL doesn't support DataType.DISTANCE_TOTAL if I call supportsDistanceMilestone()
I use a real device Galaxy Watch4 (model SM-R870).
Contributor guide
Research direction
Start with the exercise setup and preparation code included in the issue, then inspect the Health Services capabilities and data callbacks for SWIMMING_POOL on the Galaxy Watch4. Verify whether DISTANCE_TOTAL, SWIMMING_LAP_COUNT, and the requested preparation data are supported before and after start. Done means documenting the limitation or updating the sample so supported distance and lap events are received.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100