android 健康连接错误:应用程序必须在前台才能读取以下数据类型

kuarbcqp  于 2023-02-17  发布在  Android
关注(0)|答案(1)|浏览(94)

我们的应用程序集成了Health Connect,我在Firebase Crashlytics中看到了很多以下非致命错误:

Non-fatal Exception: android.os.RemoteException: xxx.xxx.xxx must be in foreground to read the following data types [ActiveTime, ActivityEvent, ActivityLap, Repetitions, ActivitySession, CyclingPedalingCadenceSeries, SwimmingStrokes]
       at androidx.health.platform.client.impl.error.ErrorStatusConverterKt.toException(ErrorStatusConverter.kt:49)
       at androidx.health.platform.client.impl.ReadDataRangeCallback.onError(ReadDataRangeCallback.kt:35)
       at androidx.health.platform.client.service.IReadDataRangeCallback$Stub.onTransact(IReadDataRangeCallback.java:75)
       at android.os.Binder.execTransactInternal(Binder.java:1321)
       at android.os.Binder.execTransact(Binder.java:1280)

此错误来自何处?建议的解决方案是什么?
谢谢
编辑:我还看到以下新错误:

Fatal Exception: android.os.RemoteException: Binder died
       at androidx.health.platform.client.impl.ipc.internal.ServiceConnection.lambda$new$0(ServiceConnection.java:111)
       at androidx.health.platform.client.impl.ipc.internal.ServiceConnection.$r8$lambda$2SQ9wD-9H8TwP52A7SNlzsrM2RI(ServiceConnection.java)
       at androidx.health.platform.client.impl.ipc.internal.ServiceConnection$$InternalSyntheticLambda$1$8858e53f1ea91e6694f6e04c25caaf42f7b9742af4af96e2c4e06ac75ef72d54$0.binderDied(ServiceConnection.java:2)
       at android.os.IBinder$DeathRecipient.binderDied(IBinder.java:320)
       at android.os.BinderProxy.sendDeathNotice(BinderProxy.java:750)
    ```
wfsdck30

wfsdck301#

当您从非UI/后台线程调用Health Connect读取API时,您收到该错误。我们的文档中引用了该错误:https://developer.android.com/guide/health-and-fitness/health-connect/platform-overview/developer-functionality#reading_with_health_connect
请确保每当阅读HC上的记录时,应在前台使用您的应用程序进行呼叫。

相关问题