Не удается подключиться к носимым медицинским службам Android
Я попытался прочитать шаги ходьбы из 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, но безуспешно.
1 ответ
У меня была такая же проблема с моими Galaxy Watch 4, и я нашел ее в одном из образцов Google, и это исправило ее для меня.
AndroidМанифест:
<queries>
<package android:name="com.google.android.wearable.healthservices" />
</queries>