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

feat: add `READ_HEALTH_DATA_HISTORY` permission

Open bharat-nair opened this issue 7 months ago • 6 comments

This PR adds the READ_HEALTH_DATA_HISTORY that lets apps read health data beyond the default limit of 30 days.

  • Updated Health Connect dependency to androidx.health.connect:connect-client:1.1.0-alpha11 because support for this permission is available since alpha10 and above. link
  • This change requires compileSdkVersion to be 35.

I have tested my changes against an Android 13 device, and it works: Screenshot

However, I am unable to get this permission to work on an Android 14 device. I have no knowledge of Kotlin and I was mostly able to make this work by 'breadcrumb-ing' the ExerciseRoute types and methods throughout this project.

Edit: The Android 14 device is a Samsung device running OneUI 6.1, so it could also be something funky that Samsung is doing.

bharat-nair avatar Apr 06 '25 18:04 bharat-nair

Excited for this addition 👍

shmkane avatar Apr 09 '25 14:04 shmkane

@bharat-nair try to mark @matinzd as reviewer

davkub avatar Apr 24 '25 10:04 davkub

I was hoping someone might have a look at the code and provide some feedback as to why I am unable to get this working on the Android 14 device. Nevertheless, @matinzd please have a look at this PR. Thanks!

bharat-nair avatar Apr 25 '25 07:04 bharat-nair

hi @bharat-nair The permission READ_HEALTH_DATA_HISTORY has only been added in Android 35 (source)

From Google's documentation we can read that the 30 days read limitation can only be bypassed with this permission : https://developer.android.com/health-and-fitness/guides/health-connect/develop/read-data#30-day-restriction

This is why you're not able to make it work on Android 14, it's not a Samsung funky thing unfortunately.

So, I suppose we'll never be able to read data from Health Connect further than 30 days on a device that is not running Android 15. It's kinda sad, but it seems to be a limitation and we'll have to deal with it.

However, I'd be happy if someone proves me I'm wrong 😅

PaulDardaine avatar Apr 25 '25 11:04 PaulDardaine

hi @bharat-nair The permission READ_HEALTH_DATA_HISTORY has only been added in Android 35 (source)

From Google's documentation we can read that the 30 days read limitation can only be bypassed with this permission : https://developer.android.com/health-and-fitness/guides/health-connect/develop/read-data#30-day-restriction

This is why you're not able to make it work on Android 14, it's not a Samsung funky thing unfortunately.

So, I suppose we'll never be able to read data from Health Connect further than 30 days on a device that is not running Android 15. It's kinda sad, but it seems to be a limitation and we'll have to deal with it.

However, I'd be happy if someone proves me I'm wrong 😅

I think you're right! Thanks for providing the source there. Upon closer inspection, it seems that there is an SDK Extensions feature that provides backwards compatibility of some newer APIs to older Android versions. This health data history permissions is provided in the U Extensions 13 (you can see it in your source). However, support for this extension varies with OEMs I believe.

You can check if your device supports this extension using adb. If the output shows something like [build.version.extensions.u]: [13] or similar, then I believe this permission should work. Unfortunately, my Android 14 device seems to only show [build.version.extensions.u]: [12] so I guess I'll have to wait for an update.

bharat-nair avatar Apr 26 '25 10:04 bharat-nair

@bharat-nair Looks like you got yourself an approve, good job 🚀

davkub avatar May 12 '25 11:05 davkub

I tested this and it's working perfectly! Good job and thanks @bharat-nair

matinzd avatar May 19 '25 20:05 matinzd