3

我尝试使用本指南阅读 Android Wear(Samsung Galaxy Watch 4)的步行步骤:https ://developer.android.com/training/wearables/health-services/active 。

这是我的代码的一部分:

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

但我收到了这个例外:

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)

注意:上面的指南中有一个注释要获取权限,但没有提到哪些权限。我尝试了 ACTIVITY_RECOGNITION 和 BODY_SENSORS 和 ACCESS_FINE_LOCATION,但没有成功。

4

1 回答 1

0

我的 Galaxy Watch 4 也有同样的问题,我在 Google 的一个样本中发现了这个问题,它为我修复了它

安卓清单:

<queries>
 <package android:name="com.google.android.wearable.healthservices" />
</queries>
于 2021-12-24T12:00:03.557 回答