HealtConnect error: app must be in foreground to read the following data types

564 views Asked by At

Our app integrates with Health Connect, and I see a lot of following non-fatal errors in 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)

Where does this error come from, and what is a suggested solution?

Thank you

EDIT: I also see the following new error:

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)
    ```
1

There are 1 answers

0
BearDroid On

You are receiving that error as you were calling Health Connect Read APIs from a non-UI/background thread. This is cited on our documentation here : https://developer.android.com/guide/health-and-fitness/health-connect/platform-overview/developer-functionality#reading_with_health_connect

Please make sure that whenever reading records on HC, the calls should be made with your app on the foreground.