react-native-health-connect icon indicating copy to clipboard operation
react-native-health-connect copied to clipboard

Background Delivery

Open mohamadfala opened this issue 1 year ago • 5 comments

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.

mohamadfala avatar Apr 05 '24 20:04 mohamadfala

You can check the proof of concept of this in this tree:

https://github.com/matinzd/react-native-health-connect/tree/headless_poc

matinzd avatar Apr 23 '24 12:04 matinzd

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.

lsandini avatar Oct 14 '24 18:10 lsandini

Very nice! Did the PoC help you? @lsandini

matinzd avatar Oct 15 '24 13:10 matinzd

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

lsandini avatar Oct 16 '24 06:10 lsandini

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?

niklas-simon avatar Feb 07 '25 15:02 niklas-simon