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

Facing Consent required error while trying to read ExerciseSession

Open abey-thomas opened this issue 1 year ago • 3 comments

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?

abey-thomas avatar Apr 22 '24 10:04 abey-thomas

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

abey-thomas avatar Apr 22 '24 13:04 abey-thomas

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

matinzd avatar Apr 23 '24 12:04 matinzd

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

ugurakin1 avatar Oct 09 '24 16:10 ugurakin1