react-native-health-connect
react-native-health-connect copied to clipboard
Background Delivery
I would like to implement the ability to receive data from the health connect integration in the background without using background tasks with periodic updates. Is there any way to listen to an even in the background that will fire a synchronization method in my application and send new records to the server?
I was able to accomplish this in React Native Healthkit using NativeEmitter.
You can check the proof of concept of this in this tree:
https://github.com/matinzd/react-native-health-connect/tree/headless_poc
https://developer.android.com/health-and-fitness/guides/health-connect/develop/read-data
This page last updated 2024-09-30 UTC and states: "Health Connect allows apps to read data from the datastore when the app is in the foreground and background"
And it works ! I tested setting up a background-fetch that queries Health Connect for step counts in the background, and also triggering the task in the background using a silent push notification from my backend. Steps are returned as expected.
Very nice! Did the PoC help you? @lsandini
I wasn't even aware of the PoC, Here is how I did it, in my little test app (branch silent4)
https://github.com/lsandini/walker/tree/silent4
Health Connect queries returned an error as I tried to run them as a background task, now the step count is retrieved correctly
I seem to be unable to write data from the background. It seems to be stuck on checking permissions and when I don't check permissions it gets stuck on insertRecords. What am I doing wrong?