react-native-health-connect
react-native-health-connect copied to clipboard
feat: add `READ_HEALTH_DATA_HISTORY` permission
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-alpha11because support for this permission is available since alpha10 and above. link - This change requires
compileSdkVersionto be35.
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.
Excited for this addition 👍
@bharat-nair try to mark @matinzd as reviewer
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!
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 😅
hi @bharat-nair The permission
READ_HEALTH_DATA_HISTORYhas 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 Looks like you got yourself an approve, good job 🚀
I tested this and it's working perfectly! Good job and thanks @bharat-nair