-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds a new method for requesting exercise permissions (#167)
* feat: adds a new method for requesting exercise permissions * feat: changes request permission interface to include a flag for route permissions * chore: reverted code formatting * chore: remove merge cursor * chore: reverted more formatting changes * chore: minor diff clean up * feat: bubbles up exercise route result type * feat: bubbles up consent + adds a permission type for exercise route * chore: removed unused imports and log statements * docs: corrected comment * docs: updated docs for request permission * docs: added docs for the new api
- Loading branch information
Showing
15 changed files
with
330 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<application> | ||
<uses-permission | ||
android:name="android.permission.health.READ_EXERCISE_ROUTES" /> | ||
<uses-permission | ||
android:name="android.permission.health.READ_EXERCISE" /> | ||
... | ||
</application> | ||
``` | ||
|
||
# Method | ||
|
||
```ts | ||
requestExerciseRoute(recordId: string): Promise<ExerciseRoute> | ||
``` | ||
|
||
# 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 }); | ||
}); | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.