OiO.lk Blog Android WearOS, startExercise is giving Missing Permission error
Android

WearOS, startExercise is giving Missing Permission error


I am developing an app for Samsung Watch 6 (WearOS), using Android’s health services API.

It used to work fine a few months back. Maybe the WearOS got updated or maybe it is related to the libraries I updated of my project after a few months.

When I call:

healthServicesClient.exerciseClient.startExercise(config)

I am getting following error, which does not mention which permission:

java.lang.SecurityException: Missing permissions
at androidx.health.services.client.impl.internal.StatusCallback.onFailure(StatusCallback.kt:43)
at androidx.health.services.client.impl.internal.IStatusCallback$Stub.onTransact(IStatusCallback.java:74)
at android.os.Binder.execTransactInternal(Binder.java:1285)
at android.os.Binder.execTransact(Binder.java:1244)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@156f238, Dispatchers.Main.immediate]

Below are the permissions set in Manifest:

<uses-permission android:name="android.permission.BODY_SENSORS" />
<uses-permission android:name="android.permission.BODY_SENSORS_BACKGROUND" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

I am also asking permissions in my Fragment

permissionLauncher.launch(REQUIRED_PERMISSIONS)

Below is the whole config I set for startExcercise(config)

val capabilities = getExerciseCapabilities() ?: return
        val dataTypes = setOf(
            DataType.HEART_RATE_BPM,
            DataType.CALORIES_TOTAL,
            DataType.STEPS_TOTAL,
            DataType.DISTANCE
        ).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.
            exerciseGoals.add(
                ExerciseGoal.createMilestone(
                    condition = DataTypeCondition(
                        dataType = DataType.DISTANCE_TOTAL,
                        threshold = DISTANCE_THRESHOLD,
                        comparisonType = ComparisonType.GREATER_THAN_OR_EQUAL
                    ),
                    period = DISTANCE_THRESHOLD
                )
            )
        }

        val config = ExerciseConfig(
            exerciseType = ExerciseType.RUNNING,
            dataTypes = dataTypes,
            isAutoPauseAndResumeEnabled = false,
            isGpsEnabled = true,
            exerciseGoals = exerciseGoals
        )
        exerciseClient.startExercise(config)



You need to sign in to view this answers

Exit mobile version