health-samples
health-samples copied to clipboard
swim distance, lap count
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<ExerciseGoal<Double>>()
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).
Does your app let the user choose between Open_Water_Swim and Swimming_Pool? Open_Water_Swim doesn't support laps.
Also, are you testing with real-world conditions (i.e. testing while swimming)?
yes, my app supports 2 swim styles. I've simulated swimming. So, in both cases, the distance doesn't work, and calories don't work for the pool swim style. (when I use an emulator, the distance works fine) Also when I tested by emulator I couldn't start the pool swim, because I caught an exception about pool size. But for a real device it doesn't reproduce.
exerciseClient.startExerciseAsync(config).await()
"If exercise type is SWIMMING_POOL, then swimming pool length must also be specified"
Let me know, please, how to solve these issues.
That exception is thrown when the pool size is either unspecified or when it equals 0. I'm not sure from the code exactly why it is being thrown only when using the emulator, but I can try to look into this.
Hello, any news?
- Did you fix this issue?
- When will be the next version the library with fixed issues?
I am also encountering the issue of no lap or distance data coming in on androidx.health:health-services-client:1.0.0-rc01
on a Samsung Galaxy 5 (SM-4910). I am testing on hardware and "virtually swimming" in place around my office by swinging my arm in a swimming motion, which works with the Samsung app and others to trigger distance/laps to appear.
After registering a ExerciseUpdateCallback
I can see that types "Swimming Strokes" "Calories" and "HeartRate" are requested (reported as ACQUIRING
) but only "Heart Rate" is ever reporting as AVAILABLE
in onAvailabilityChanged()
. I would expect that all of the requested types (DISTANCE
, DISTANCE_TOTAL
, SWIMMING_LAP_COUNT
, etc) would also be requested but also approved.
Permissions are enabled for types android.Manifest.permission.BODY_SENSORS
and android.Manifest.permission.ACTIVITY_RECOGNITION
.
Any ideas?
@onix-flutter-dev can you share the Health Services version details for your Galaxy Watch 4? We want to check if the issue is specific to a version of WHS.
You can run adb shell dumpsys package com.google.android.wearable.healthservices | grep -E "versionCode|versionName"
@breanatate adb shell dumpsys....... versionCode=361255 minSdk=30 targetSdk=33 versionName=0.23.8.538258079 versionCode=77257 minSdk=30 targetSdk=30 versionName=0.8.30.449110343
After updating to Wear OS 4.0 that came out yesterday for Samsung Galaxy Watch 5 this issue seems to be resolved for me. Will test in a pool next week.