wearable_health

A flutter plugin for reading health data from wearable health data stores. The current implementation allows reading data from Health Connect and HealthKit. Implemented health metrics are heart rate, heart rate variability, and skin temperature.

Getting Started

Installation

Install the plugin through flutter pub get wearable_health

Setup

Android

For the plugin to work for Android, the Android manifest must be modified. Example of Android manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.health.READ_HEART_RATE"/>
    <uses-permission android:name="android.permission.health.READ_SKIN_TEMPERATURE"/>
    <uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY"/>


    <application
        android:label="wearable_health_example"
        android:icon="@mipmap/ic_launcher">

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:taskAffinity=""
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme"
                />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <activity
            android:name=".PermissionRationaleActivity"
            android:exported="true"
            android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar">
            <intent-filter>
                <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW_PERMISSION_USAGE"/>
                <category android:name="android.intent.category.HEALTH_PERMISSIONS"/>
            </intent-filter>
        </activity>

        <activity-alias
            android:name="ViewPermissionUsageActivity"
            android:exported="true"
            android:targetActivity=".PermissionRationaleActivity"
            android:permission="android.permission.START_VIEW_PERMISSION_USAGE">
            <intent-filter>
                <action android:name="android.intent.action.VIEW_PERMISSION_USAGE"/>
                <category android:name="android.intent.category.HEALTH_PERMISSIONS"/>
            </intent-filter>
        </activity-alias>


        <meta-data
            android:name="flutterEmbedding"
            android:value="2"/>
    </application>

    <queries>
        <package android:name="com.google.android.apps.healthdata"/>
        <intent>
            <action android:name="android.intent.action.PROCESS_TEXT"/>
            <data android:mimeType="text/plain"/>
        </intent>
        <intent>
            <action android:name="android.intent.action.VIEW"/>
            <data android:mimeType="application/pdf"/>
        </intent>
        <intent>
            <action android:name="android.settings.APPLICATION_DETAILS_SETTINGS" />
        </intent>
        <intent>
            <action android:name="android.settings.SETTINGS" />
        </intent>
    </queries>
</manifest>

iOS

For the plugin to work for iOS, the following steps need to be taken:

  1. Add HealthKit Capabilities a. Open your Flutter project's ios folder in Xcode (YourProject/ios/Runner.xcworkspace). b. Select the Runner project in the Project navigator. c. Select the Runner target. d. Go to the Signing & Capabilities tab. e. Click the + Capability button. f. Search for and select HealthKit. This will add the HealthKit entitlement to your app.

(You can include a similar screenshot or link to Apple's documentation for this step)

  1. Add Usage Descriptions (Info.plist) You must provide descriptions for why your app needs to access HealthKit data. iOS will show these descriptions to the user when your app requests permission.

a. In Xcode, open the Info.plist file located in the Runner folder. b. Add the following keys and provide clear, user-facing descriptions as their string values:

  • NSHealthShareUsageDescription: (Privacy - Health Share Usage Description)
  • Purpose: Explain why your app needs to read data from HealthKit.
  • Example Value: "This app needs to access your health data (like steps and heart rate) to provide describe your app's feature, e.g., 'personalized workout summaries', 'progress tracking', 'health insights'."
  • NSHealthUpdateUsageDescription: (Privacy - Health Update Usage Description)
  • Purpose: Explain why your app needs to write or save data to HealthKit (if your plugin supports this). If your plugin is read-only, you might not strictly need this, but it's good practice to include it if there's any chance of future write capabilities.

Usage

Creating an instance

Retrieve the health store of your choice using the WearableHealth instance, for example: var wearableHealth = new WearableHealth(); var healthKit = wearableHealth.getAppleHealthKit(); var healthConnect = wearableHealth.getGoogleHealthConnect();

Functionality

Both data stores provide methods for:

  • Checking the availability of the datastore
  • Requesting permissions
  • Redirecting user to permissions settings (fallback for regular request permission flow)
  • Retrieving health data
  • Retrieving raw health data (unprocessed data)
  • Ability to convert health data to Open mHealth format through extension method on the health data object.

Health Connect specific:

  • Checking permissions (not available on iOS due to Apple privacy policy)

Libraries

constants
controller/wearable_health
extensions/open_m_health/health_connect/health_connect_data
extensions/open_m_health/health_connect/health_connect_heart_rate
extensions/open_m_health/health_connect/health_connect_heart_rate_variability
extensions/open_m_health/health_connect/health_connect_skin_temperature
extensions/open_m_health/health_kit/health_kit_body_temperature
extensions/open_m_health/health_kit/health_kit_data
extensions/open_m_health/health_kit/health_kit_heart_rate
extensions/open_m_health/health_kit/health_kit_heart_rate_variability
extensions/open_m_health/schemas/body_temperature
extensions/open_m_health/schemas/heart_rate
extensions/open_m_health/schemas/heart_rate_variability
extensions/open_m_health/schemas/heart_rate_variability_algorithm
extensions/open_m_health/schemas/heart_rate_variability_measurement_method
extensions/open_m_health/schemas/ieee_1752/descriptive_statistic
extensions/open_m_health/schemas/ieee_1752/duration_unit_value
extensions/open_m_health/schemas/ieee_1752/ieee_1752_schema
extensions/open_m_health/schemas/ieee_1752/temperature_unit
extensions/open_m_health/schemas/ieee_1752/temperature_unit_value
extensions/open_m_health/schemas/ieee_1752/time_frame
extensions/open_m_health/schemas/ieee_1752/time_interval
extensions/open_m_health/schemas/ieee_1752/unit_value
extensions/open_m_health/schemas/measurement_location
extensions/open_m_health/schemas/open_m_health_schema
extensions/open_m_health/schemas/temporal_relationship_to_physical_activity
extensions/open_m_health/schemas/temporal_relationship_to_sleep
model/health_connect/enums/hc_availability
model/health_connect/enums/hc_health_metric
model/health_connect/hc_entities/heart_rate
model/health_connect/hc_entities/heart_rate_record_sample
model/health_connect/hc_entities/heart_rate_variability_rmssd
model/health_connect/hc_entities/metadata
model/health_connect/hc_entities/skin_temperature
model/health_connect/hc_entities/skin_temperature_delta
model/health_connect/hc_entities/temperature
model/health_connect/hc_entities/temperature_delta
model/health_connect/health_connect_data
model/health_data
model/health_kit/enums/hk_availability
model/health_kit/enums/hk_health_metric
model/health_kit/health_kit_data
model/health_kit/hk_body_temperature
model/health_kit/hk_entities/hk_device
model/health_kit/hk_entities/hk_object_type
model/health_kit/hk_entities/hk_quantity
model/health_kit/hk_entities/hk_quantity_sample
model/health_kit/hk_entities/hk_quantity_type
model/health_kit/hk_entities/hk_sample
model/health_kit/hk_entities/hk_sample_type
model/health_kit/hk_entities/hk_source
model/health_kit/hk_heart_rate
model/health_kit/hk_heart_rate_variability
service/converters/json/json_converter
service/converters/json/json_converter_interface
service/factory/factory
service/factory/factory_interface
service/health_connect/data_factory
service/health_connect/data_factory_interface
service/health_connect/health_connect
service/health_connect/health_connect_interface
service/health_kit/data_factory
service/health_kit/data_factory_interface
service/health_kit/health_kit
service/health_kit/health_kit_interface