From 4d097deeac3131b4c87d7573d568a1f57d3986bf Mon Sep 17 00:00:00 2001 From: Ugur Akin Date: Sat, 2 Nov 2024 18:31:30 +0000 Subject: [PATCH] docs: added docs for the new api --- .../api/methods/16-requestExerciseRoute.md | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 docs/docs/api/methods/16-requestExerciseRoute.md diff --git a/docs/docs/api/methods/16-requestExerciseRoute.md b/docs/docs/api/methods/16-requestExerciseRoute.md new file mode 100644 index 0000000..db9e8e5 --- /dev/null +++ b/docs/docs/api/methods/16-requestExerciseRoute.md @@ -0,0 +1,59 @@ +--- +title: requestExerciseRoute +--- + +# `requestExerciseRoute` + +Health Connect requires users' permission to access routes for exercise records ([see Android docs](https://developer.android.com/health-and-fitness/guides/health-connect/develop/exercise-routes)). When exercise records are fetched, they will include an `exerciseRoute` field with a `type` (and possibly a `route`). This method should be called to request permissions to fetch the route if the `type` is `ExerciseRouteResultType.CONSENT_REQUIRED`. + +NOTE: To read exercise routes, you need to declare the required permissions in your app's `AndroidManifest.xml`: + +```xml + + + +... + +``` + +# Method + +```ts +requestExerciseRoute(recordId: string): Promise +``` + +# Example + +```ts +import { + requestExerciseRoute, + readRecord, + ExerciseRouteResultType, +} from "react-native-health-connect"; + +const recordId = "6bd8109d-349b-319a-890a-c5a20902b530"; + +readRecord("ExerciseSession", recordId) + .then((exercise) => { + console.log("Exercise record: ", JSON.stringify(exercise, null, 2)); + + // Check if consent is required to read route: + if ( + exercise.exerciseRoute.type === ExerciseRouteResultType.CONSENT_REQUIRED + ) { + requestExerciseRoute(recordId).then(({ route }) => { + if (route) { + console.log(JSON.stringify(route, null, 2)); + } else { + console.log("User denied access"); + } + }); + } + }) + .catch((err) => { + console.error("Error reading exercise record", { err }); + }); + +``` \ No newline at end of file