这是indexloc提供的服务,不要输入任何密码

wearable_health 0.0.2 copy "wearable_health: ^0.0.2" to clipboard
wearable_health: ^0.0.2 copied to clipboard

A flutter plugin for reading health data

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)
0
likes
140
points
57
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter plugin for reading health data

Repository
View/report issues

Topics

#health #fitness #healthkit #healthconnect #wearable

Documentation

Documentation
API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on wearable_health