Capacitor plugin for Apple Health and Google Health Connect
npm install capacitor-healthCapacitor plugin to query data from Apple Health and Google Health Connect
Some parts, concepts and ideas are borrowed from cordova-plugin-health. Big thanks to @dariosalvi78 for the support.
``bash`
npm install capacitor-health
npx cap sync
* Make sure your app id has the 'HealthKit' entitlement when this plugin is installed (see iOS dev center).
* Also, make sure your app and App Store description comply with the Apple review guidelines.
* There are two keys to be added to the info.plist file: NSHealthShareUsageDescription and NSHealthUpdateUsageDescription.
* Android Manifest in application tag
`xml
android:exported="true">
android:exported="true"
android:targetActivity="com.fit_up.health.capacitor.PermissionsRationaleActivity"
android:permission="android.permission.START_VIEW_PERMISSION_USAGE">
`
* Android Manifest in root tag
`xml`
* isHealthAvailable()
* checkHealthPermissions(...)
* requestHealthPermissions(...)
* openAppleHealthSettings()
* openHealthConnectSettings()
* showHealthConnectInPlayStore()
* queryAggregated(...)
* queryWorkouts(...)
* Interfaces
* Type Aliases
`typescript`
isHealthAvailable() => Promise<{ available: boolean; }>
Checks if health API is available.
Android: If false is returned, the Google Health Connect app is probably not installed.
See showHealthConnectInPlayStore()
Returns: Promise<{ available: boolean; }>
--------------------
`typescript`
checkHealthPermissions(permissions: PermissionsRequest) => Promise
Android only: Returns for each given permission, if it was granted by the underlying health API
| Param | Type | Description |
| ----------------- | ----------------------------------------------------------------- | -------------------- |
| permissions | PermissionsRequest | permissions to query |
Returns: Promise<PermissionResponse>
--------------------
`typescript`
requestHealthPermissions(permissions: PermissionsRequest) => Promise
Requests the permissions from the user.
Android: Apps can ask only a few times for permissions, after that the user has to grant them manually in
the Health Connect app. See openHealthConnectSettings()
iOS: If the permissions are already granted or denied, this method will just return without asking the user. In iOS
we can't really detect if a user granted or denied a permission. The return value reflects the assumption that all
permissions were granted.
| Param | Type | Description |
| ----------------- | ----------------------------------------------------------------- | ---------------------- |
| permissions | PermissionsRequest | permissions to request |
Returns: Promise<PermissionResponse>
--------------------
`typescript`
openAppleHealthSettings() => Promise
Opens the apps settings, which is kind of wrong, because health permissions are configured under:
Settings > Apps > (Apple) Health > Access and Devices > [app-name]
But we can't go there directly.
--------------------
`typescript`
openHealthConnectSettings() => Promise
Opens the Google Health Connect app
--------------------
`typescript`
showHealthConnectInPlayStore() => Promise
Opens the Google Health Connect app in PlayStore
--------------------
`typescript`
queryAggregated(request: QueryAggregatedRequest) => Promise
Query aggregated data
| Param | Type |
| ------------- | ------------------------------------------------------------------------- |
| request | QueryAggregatedRequest |
Returns: Promise<QueryAggregatedResponse>
--------------------
`typescript`
queryWorkouts(request: QueryWorkoutRequest) => Promise
Query workouts
| Param | Type |
| ------------- | ------------------------------------------------------------------- |
| request | QueryWorkoutRequest |
Returns: Promise<QueryWorkoutResponse>
--------------------
#### PermissionResponse
| Prop | Type |
| ----------------- | ------------------------------------------ |
| permissions | { [key: string]: boolean; }[] |
#### PermissionsRequest
| Prop | Type |
| ----------------- | ------------------------------- |
| permissions | HealthPermission[] |
#### QueryAggregatedResponse
| Prop | Type |
| -------------------- | ------------------------------- |
| aggregatedData | AggregatedSample[] |
#### AggregatedSample
| Prop | Type |
| --------------- | ------------------- |
| startDate | string |
| endDate | string |
| value | number |
#### QueryAggregatedRequest
| Prop | Type |
| --------------- | ---------------------------------- |
| startDate | string |
| endDate | string |
| dataType | 'steps' \| 'calories' |
| bucket | string |
#### QueryWorkoutResponse
| Prop | Type |
| -------------- | ---------------------- |
| workouts | Workout[] |
#### Workout
| Prop | Type |
| -------------------- | ------------------------------ |
| startDate | string |
| endDate | string |
| workoutType | string |
| sourceName | string |
| id | string |
| duration | number |
| distance | number |
| calories | number |
| sourceBundleId | string |
| route | RouteSample[] |
| heartRate | HeartRateSample[] |
#### RouteSample
| Prop | Type |
| --------------- | ------------------- |
| timestamp | string |
| lat | number |
| lng | number |
| alt | number |
#### HeartRateSample
| Prop | Type |
| --------------- | ------------------- |
| timestamp | string |
| bpm | number |
#### QueryWorkoutRequest
| Prop | Type |
| ---------------------- | -------------------- |
| startDate | string |
| endDate | string |
| includeHeartRate | boolean |
| includeRoute` | boolean |
#### HealthPermission
'READ_STEPS' | 'READ_WORKOUTS' | 'READ_CALORIES' | 'READ_DISTANCE' | 'READ_HEART_RATE' | 'READ_ROUTE'