health-samples
health-samples copied to clipboard
SWIMMING_OPEN_WATER distance 0 in real time
Hello. I use ExerciseType.SWIMMING_OPEN_WATER. val dataTypes = setOf( DataType.HEART_RATE_BPM, DataType.LOCATION, DataType.DISTANCE, ).intersect(capabilities.supportedDataTypes)
val aggDataTypes = setOf(
DataType.TOTAL_CALORIES,
DataType.DISTANCE,
DataType.LOCATION, // +++
DataType.SWIMMING_STROKES
).intersect(capabilities.supportedDataTypes)
Usually, I see responses distance 0, but when I call exerciseClient.endExercise().await() I see total distance. For ExerciseType.SWIMMING_POOL distance works. How to get the distance in real time?
Hello, just to make sure I fully understand the scenario in order to replicate it:
- Are you using the Health Services emulator or testing with real data?
- You want to view the total distance in real time, but currently are only able to see total distance once the exercise completes?
- I use a device for testing (Galaxy Watch4 (V7YJ))
- Not really, when exercise (ExerciseType.SWIMMING_OPEN_WATER) running I see the distance 0 every time, but when I call endExercise().await() I see the total distance (like 0.02km). I want to see the distance when the exercise running.
- When I use ExerciseType.SWIMMING_POOL - the distance changing in real time. And total distance works. This type works correctly.
Are you testing this by swimming? For the Galaxy Watch 4 in particular, there needs to be some degree of regular arm movement for the device to count distance traveled as swimming distance. If you test with the emulator, you'll see that the distance updates in real-time.
This morning, I tested with the Galaxy Watch 4 and was only able to see distance updates in real-time while mimicking swimming with my arms. I started with both arms reaching straight out, about level with my chin, and then pretended to do a freestyle stroke, returning my arm to its starting position each time. I also decreased the distance to meters to make sure I would be able to notice small changes in distance (yards is more common in swimming and would also work).
Thanks. I'll try mimicking swimming too.
Sorry. Can you share your functions (fun startExercise(), fun prepareExercise())? I still see distance 0.
I used the startExercise and prepareExercise functions from the sample, but added the snippets you had above. I also kept the distance metric at meters instead of KMs.
`suspend fun startExercise() { Log.d(TAG, "Starting exercise") // Types for which we want to receive metrics. Only ask for ones that are supported. val capabilities = getExerciseCapabilities() ?: return val dataTypes = setOf( DataType.HEART_RATE_BPM, DataType.DISTANCE, DataType.LOCATION ).intersect(capabilities.supportedDataTypes)
val aggDataTypes = setOf(
DataType.TOTAL_CALORIES,
DataType.DISTANCE,
DataType.LOCATION,
// +++
DataType.SWIMMING_STROKES
).intersect(capabilities.supportedDataTypes)`
and `suspend fun prepareExercise() { Log.d(TAG, "Preparing an exercise")
val warmUpConfig = WarmUpConfig.builder()
.setExerciseType(ExerciseType.SWIMMING_OPEN_WATER)
.setDataTypes(
setOf(
DataType.HEART_RATE_BPM,
DataType.LOCATION
)
)
.build()`