react-native-health-connect
react-native-health-connect copied to clipboard
ElevationGained returns empty array
Describe the bug I've logged an ExerciseSession (Samsung Health and Google Fit) which includes elevation gained. It syncs but the request to readRecords for ElevationGained returns an empty array. Distance comes back and the basic activity details, but no elevation.
To Reproduce Steps to reproduce the behavior:
- Log an exercise session activity
- Sync with Health Connect
- Sync with an app using
react-native-health-connect - Request elevation for the exercise session
- Empty array is returned
Expected behavior
Should return an array of elevation records, like the readRecords for 'Distance' that includes inMeters, etc.
Minimal Reproducible
const rawActivities = await readRecords('ExerciseSession', {
timeRangeFilter: {
operator: 'after',
startTime: from.toISOString()
},
});
let activities = []
// for each activity additional reads are required to pull distance and elevation
for (const a of rawActivities) {
const rawDistance = await readRecords('Distance', {
timeRangeFilter: {
operator: 'between',
startTime: a.startTime,
endTime: a.endTime
}
});
const distance = rawDistance.reduce((acc, item) => {
return acc += item.distance.inMeters
}, 0)
// distance is working great and returns values here
const rawElevation = await readRecords('ElevationGained', {
timeRangeFilter: {
operator: 'between',
startTime: a.startTime,
endTime: a.endTime
}
});
// rawElevation is empty array
console.log('rawElevation', rawElevation)
const elevation = rawElevation.reduce((acc, item) => {
return acc += item.elevation.inMeters
}, 0)
activities.push({ ...a, distance, elevation })
}
Environment:
- Health Connect Version: 2.0.3
- React Native Version: "0.73.5"
- New architecture enabled: ?
- Using Expo: Prebuild(Dev Client)
Hey!
Are you seeing any errors in ADB in Android Studio or It just returns empty array? Did you try putting it in try catch and see if an exception happens?
@matinzd thanks for the response. There are no errors logged and the function successfully returns an empty array. It does not throw an error. Do you have any examples of this working?
I'm having the same issue with the power data...
But starting with the elevation gain case (and using Samsung Health). Google Fit doesn't have the option to add elevation manually (at least I didn't find it): I've checked Health Connect and the elevation gain data isn't there (maybe Samsung Health didn't publish it?).
In the case of power, I entered the exercise manually via Google Fit and when checking this data on my app, the array comes empty. I checked on Health Connect and the potency data was there. I opened this issue: https://github.com/matinzd/react-native-health-connect/issues/125
Have you added any ElevationGained records? It seems that both you and @gabrielgouv might be assuming these values are automatically calculated based on the ExerciseSession, but that’s not the case. Health Connect should be viewed as a data store for different entities, and it doesn't automatically compute values based on other entities, as far as I know.
In both of your cases, it looks like you expect that by entering ExerciseSession data, you would also get ElevationGained and Power data from Health Connect. However, I don't believe that's the intended purpose of Health Connect.
I have used Google Fit with a device and recorded a true activity with real elevation gain (not manually entered) and exercise session data comes through, just no elevation gain. The array is empty.
Did you check Health Connect app to see if ElevationGained data is there for that specific timeframe?