android / health-samples

Apache License 2.0
248 stars 142 forks source link

Need to read Heart Rate, Location and Daily Steps Data using Passive data client every hour #190

Closed tsols closed 8 months ago

tsols commented 8 months ago

I am new to the platform, trying to read Heart Rate, Location Coordinates, and Daily Steps data using PassiveListenerService, but i need to be able to read this data every Hour from Galaxy Watch 5, not sure how is that possible from Passive Data sample, I am not sure if there is a way to set the Data reading frequency (Like read Heart Rate, Location Coordinates and Daily Steps every 1 to 2 hours)? Also what is the difference in PassiveData and PassiveDataCompose sample Projects?

breanatate commented 8 months ago

Hello,

There is no way to set the update frequency within PassiveMonitoringClient itself. You would need to set that up separately using something like WorkManager to batch the data to your app (from wherever its stored) at the frequency of an hour.

PassiveData and PassiveDataCompose have the same functionality, but one is built using Views and the other using Compose.

tsols commented 8 months ago

Hello,

There is no way to set the update frequency within PassiveMonitoringClient itself. You would need to set that up separately using something like WorkManager to batch the data to your app (from wherever its stored) at the frequency of an hour.

PassiveData and PassiveDataCompose have the same functionality, but one is built using Views and the other using Compose.

Instead of WorkManager, if Samsung Health App is collecting that health data every 10 minutes, that data will accumulate and be read in PassiveMonitoringClient?

breanatate commented 8 months ago

You can read Heart Rate and Steps written by Samsung Health from Health Connect . The only caveat is that Samsung Health may not write the data to Health Connect as frequently as every 10 minutes.

tsols commented 8 months ago

You can read Heart Rate and Steps written by Samsung Health from Health Connect . The only caveat is that Samsung Health may not write the data to Health Connect as frequently as every 10 minutes.

What i am trying to achieve is reading HR(bpm), Daily Steps(count) ,Location (coordinates) directly on wearOS app and send to an API hosted on a cloud, from my tests with Health Connect, it is Mobile only App and API. So not sure if what i am trying to do is even possible with Health Connect API, My Standalone WearOS App should be able to send data directly to cloud via API, without needing phone.

Now back to original question, what triggers PassiveMonitoringClient that there is new data to be read?

breanatate commented 8 months ago

Frequency of data return intervals depends on the device and the data type. You can find more information here. Factors for what can trigger the data to be sent include the sensor buffers being full, or the user interacting with the device.

If you need steps frequently, I would suggest using Steps instead of Daily Steps since Daily Steps is only returned at midnight.

If you use ExerciseClient instead of PassiveMonitoringClient, the data would be sent more frequently, but it would require your app to be running a foreground service the entire time you're consuming data.

tsols commented 8 months ago

Frequency of data return intervals depends on the device and the data type. You can find more information here. Factors for what can trigger the data to be sent include the sensor buffers being full, or the user interacting with the device.

If you need steps frequently, I would suggest using Steps instead of Daily Steps since Daily Steps is only returned at midnight.

If you use ExerciseClient instead of PassiveMonitoringClient, the data would be sent more frequently, but it would require your app to be running a foreground service the entire time you're consuming data.

You mentioned WorkManager to schedule collection of data at regular intervals , what i understood from that earlier post that PassiveMonitoringClient within my app will read data when WorkManager (in a separate app) runs a scheduled event as specified interval, please confirm if that is correct? My App will be kind of background app running to collect HR, Steps and location data every hour or so and posting to an API.

tsols commented 8 months ago

@breanatate do you know if we add additional functionality to Passive Data sample app ( like Reading or Writing to an API every few hours) would the app still be running in the background or WearOS 4 will kill/suspend the app?

breanatate commented 8 months ago

If you declare the BODY_SENSORS_BACKGROUND permission, the app will not be killed in the background