Android HealthConnect: healthConnectClient.getChanges(token) method does not pull new data from Health Connect app

134 views Asked by At

I recently started working with HealthConnect SDK for Android (Kotlin), i am able to check permissions, enable them, revoke them and read data but i am not able to pull updates from Health Connect app.

Calling:

val response = healthConnectClient.getChanges(nextChangesToken)

never return changes (I used HealthConnect Toolbox app to insert new Steps data in healthConnect app, so i am sure there are new changes to be fetched).

I make sure i check and enable permissions (READ steps) before calling the method.

Anyone had similar scenario? i really appreciate any hint :)

1

There are 1 answers

0
Kaouther Mefteh On BEST ANSWER

Would like to share my finding with this issue maybe would help someone out there. So for me the issue was that i was calling

val nextChangesToken = healthconnectClient.getChangeToken(..)

everytime i am calling healthconnectClient.getChanges(nexChangesToken) (in button click) which is wrong cause the nextChangesToken is for the next call of getchanges and will fetch next data if available.

The right way to do it is to call healthconnectClient.getChangeToken(..) once (ofcourse there is validation condition that should be checked: since this token valide for 30 day only) and in different action (click button or so) call getchanges(token)