react-native-health-connect
react-native-health-connect copied to clipboard
Facing Consent required error while trying to read ExerciseSession
Hi team, I am trying to read and write ExerciseSession record
Below permissions are added in androidManifest
<uses-permission android:name="android.permission.health.READ_EXERCISE" />
<uses-permission android:name="android.permission.health.WRITE_EXERCISE" />
<uses-permission android:name="android.permission.health.READ_EXERCISE_ROUTE" />
<uses-permission android:name="android.permission.health.WRITE_EXERCISE_ROUTE" />
Permissions are requested with below code
await requestPermission([
{ accessType: "read", recordType: "Steps" },
{ accessType: "read", recordType: "ActiveCaloriesBurned" },
{ accessType: "read", recordType: "ExerciseSession" },
]);
When I try to read data
await readRecords("ExerciseSession", {
timeRangeFilter: {
operator: "after",
startTime: new Date(startDate.setHours(0, 0, 0, 0)).toISOString(),
},
});
I get error: [Error: Consent required]
I see the error comes from ExerciseRouteResult.ConsentRequired
Could someone pls help to solve this?
I commented out below code in ReactExerciseSessionRecord.kt and am able to read route data as well.
is ExerciseRouteResult.ConsentRequired -> {
throw Exception("Consent required")
}
Is there a better solution to this? @matinzd
There is a better solution but unfortunately, I haven't had time to implement ExerciseRouteConsent in order for this to happen. Here is the open issue that you can follow:
https://github.com/matinzd/react-native-health-connect/issues/34
Maybe we should bubble consent required to RN/JS? Can make the exerciseRoute field an object with type and route? fields. Can include in #167