Skip to content

Install Health

To use this package, add the following to your pubspec.yaml file. Note that this package only works together with carp_mobile_sensing.

dependencies:
carp_core: ^latest
carp_mobile_sensing: ^latest
carp_health_package: ^latest
...

Then, follow the setup guides in the health plugin.

This sampling package only supports Google Health Connect. To configure your app to use Health Connect, follow the documentation on the health package and on the Android Developer page.

android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dk.cachet.carp_mobile_sensing_app"
xmlns:tools="http://schemas.android.com/tools">
<!-- Check whether Health Connect is installed or not -->
<queries>
<package android:name="com.google.android.apps.healthdata" />
<intent>
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent>
</queries>
...
<!-- Permissions for Health Connect -->
<uses-permission android:name="android.permission.health.READ_STEPS"/>
<uses-permission android:name="android.permission.health.READ_WEIGHT"/>
...
<application
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
...
<!-- Intention to show Permissions screen for Health Connect API -->
<intent-filter>
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>
</activity>

See the setup guide for iOS in the health package.

Add this permission in the Info.plist file located in ios/Runner:

ios/Runner/Info.plist
<plist version="1.0">
<dict>
...
<key>NSHealthShareUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
</dict>
</plist>

Then open your Flutter project in XCode by right clicking on the ios folder and selecting “Open in XCode”. Enable “HealthKit” by adding a capability inside the “Signing & Capabilities” tab of the Runner target’s settings.