react-native-health-connect
react-native-health-connect copied to clipboard
Getting an empty Array in every parameter request
Describe the bug Getting an empty Array in every parameter request.
Expected behavior
Hi all, I tried more than 12 parameters I needed in my app one by one but every time I'm getting an empty Array [] in response. I've attached my function calls. Am I missing something or there is some other error?
useEffect(() => {
const initializeHealthConnect = async () => {
if (Platform.OS !== 'android') {
return
}
try {
const isInitialized = await initialize()
console.log('is initialized: ', isInitialized)
if (!isInitialized) {
throw new Error('Health Connect initialization failed')
}
const grantedPermissions = await requestPermission([
{ accessType: 'read', recordType: 'Height' },
])
console.log('granted permissions: ', grantedPermissions)
if (!grantedPermissions) {
throw new Error('Permissions not granted')
}
setPermissionsGranted(true)
} catch (err) {
console.error(
'Error during initialization or permission request: ',
err,
)
setError(err.message)
setLoading(false)
}
}
initializeHealthConnect()
}, [])
useEffect(() => {
const fetchHealthData = async () => {
if (permissionsGranted) {
try {
const result = await readRecords('Height', {
timeRangeFilter: {
operator: 'between',
startTime: '2023-01-09T12:00:00.405Z',
endTime: '2024-07-15T23:53:15.405Z',
},
})
console.log('Retrieved record: ', JSON.stringify({ result }, null, 2))
setHealthData(result)
} catch (err) {
console.error('Error fetching health data: ', err)
setError(err.message)
} finally {
setLoading(false)
}
}
}
fetchHealthData()
}, [permissionsGranted])
Environment:
- Health Connect Version: 2.1.0
- React Native Version: 0.74.3
- New architecture enabled: No
- Using Expo: Prebuild(Dev Client)