Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swim distance, lap count #95

Open
onix-flutter-dev opened this issue Jun 15, 2023 · 8 comments
Open

swim distance, lap count #95

onix-flutter-dev opened this issue Jun 15, 2023 · 8 comments

Comments

@onix-flutter-dev
Copy link

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).

@breanatate
Copy link
Collaborator

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)?

@onix-flutter-dev
Copy link
Author

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.

@breanatate
Copy link
Collaborator

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.

@onix-flutter-dev
Copy link
Author

Hello, any news?

  1. Did you fix this issue?
  2. When will be the next version the library with fixed issues?
изображение

@adoxner
Copy link

adoxner commented Aug 21, 2023

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?

@breanatate
Copy link
Collaborator

@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"

@onix-flutter-dev
Copy link
Author

@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

@adoxner
Copy link

adoxner commented Sep 1, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants