Can't connect to Android Wearable Health Services

1k views Asked by At

I tried to read walking steps from Android Wear (Samsung Galaxy Watch 4), using this guide : https://developer.android.com/training/wearables/health-services/active.

This is part of my code :

val healthClient = HealthServices.getClient(this /*context*/)
        val measureClient = healthClient.measureClient
        lifecycleScope.launch {
            val capabilities = measureClient.capabilities.await()
            supportsStepCount =
                DataType.WALKING_STEPS  in capabilities.supportedDataTypesMeasure
        }

But I receive this exception :

Connection to service is not available for package 'com.google.android.wearable.healthservices' and action 'com.google.android.wearable.healthservices.MeasureClient'.
2021-09-07 11:04:18.112 4523-6821/com.daftar.galaxyface E/ServiceConnection: Connection disconnected and maximum number of retries reached.
    java.util.concurrent.CancellationException: Service not available
        at androidx.health.services.client.impl.ipc.internal.ServiceConnection.connect(ServiceConnection.java:145)
        at androidx.health.services.client.impl.ipc.internal.ServiceConnection.enqueue(ServiceConnection.java:203)
        at androidx.health.services.client.impl.ipc.internal.ConnectionManager.handleMessage(ConnectionManager.java:123)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:246)
        at android.os.HandlerThread.run(HandlerThread.java:67)

Note: There is a note in guide above to take permissions, but it did not mentioned which permissions. I tried ACTIVITY_RECOGNITION and BODY_SENSORS and ACCESS_FINE_LOCATION, but no success.

1

There are 1 answers

0
Benisz On

I had the same issue with my Galaxy Watch 4 and I found this in one of Google's sample and it fixed it for me

AndroidManifest:

<queries>
 <package android:name="com.google.android.wearable.healthservices" />
</queries>