Using Health Connect in the React Native Wrapper

React Native ==> Health Connect module

The React Native Inform SDK Wrapper offers modules which you can implement into your mobile project to power data syncing with the Health Connect health data aggregation platform.

The React Native Inform SDK Wrapper supports Health Connect for Android phones and tablets. This document lays out the installation and use of the Health Connect integration.

Health Connect allows health and fitness apps to store and share the same on-device data within a unified ecosystem. It also offers a single place for users to control which apps can read and write health and fitness data.

Health Connect combines data from a variety of fitness and health apps, including Google Fit and Samsung Health.


Installation

Health Connect has its own module in the React Native Wrapper, therefore the following modules are required to use the Health Connect integration:

  • Session (core)
  • Health Connect (healthconnect)

Installation instructions are detailed in Installation.


Session

A valid session is required in order to use the Health Connect integration in the Validic Inform SDK. See Session for more information.

Record types

The record types used in the Validic Inform Mobile SDK are described in Record Types.

Record Identifiers

More information on record identifiers can be found in Record Identifiers.

Listening for InformRecord Upload

More information on record events can be found in Record Events.

Health Connect


This project integrates Health Connect with the React Native Inform SDK Wrapper to passively collect data on behalf of an end user. Validic ensures that our Mobile SDK makes use of the minimal scopes needed for our supported data types.

Please be aware that your app will need to be released on the Play Store in order for Google to review it prior to using the Health Connect data sync. However, you do not need to publish your app in order to test Health Connect.

Please review Google's guide to get started planning your request to Google for Health Connect data access.

Migration from Google Fit to Health Connect

Changes are in progress by Android. If your app currently supports the Validic integration to Google Fit, your users will need to be notified that they will need to take action.

Users will need to use Health Connect in order to sync Google Fit data to you once the Google Fit SDKs are sunset. For more information about Google Fit and Health Connect, please see our documentation about Migrating Users from Google Fit to Health Connect.

Availability

Accessing Health Connect depends on what OS version the end user is running. Check if Health Connect is available on the device before attempting to access Health Data.

Android 14 and up

Health Connect is a system app and is therefore available on every Android device running Android >= Android 14.

Android 13 and below

For devices running Android <= Android 14 Health Connect is available as an application on the Play Store.

val status = ValidicHealthConnect.getPlatformStatus()  
when (status) {  
  HealthConnectClient.SDK_UNAVAILABLE -> {  
    // No viable integration  
  }  
  HealthConnectClient.SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED -> {  
    //Redirect to package installer to find a provider, for example:  
    val uriString = "market://details?id=$providerPackageName&url=healthconnect%3A%2F%2Fonboarding"  
    context.startActivity(  
      Intent(Intent.ACTION_VIEW).apply {  
        setPackage("com.android.vending")  
        data = Uri.parse(uriString)  
        putExtra("overlay", true)  
        putExtra("callerId", context.packageName)  
      }  
    )  
  }  
  else -> {  
    // Good to go!  
  }  
}

Accessing Sensitive Data

Data stored in Health Connect is considered sensitive. Accessing end user data requires that the user grant permission to each data type before data can be read. To get started add the permission for each data type that you want to use in your application's AndroidManifest.xml. A full list of datatypes and the necessary permissions are here.

Privacy Policy

The Permissions dialog for Health Connect displays a link that must be handled by your application to display a privacy policy when the link is clicked. Register an Activity to handle the ACTION_SHOW_PERMISSIONS_RATIONALE intent.

<application>
  ...
  <!-- For supported versions through Android 13, create an activity to show the rationale
       of Health Connect permissions once users click the privacy policy link. -->
  <activity
      android:name=".PermissionsRationaleActivity"
      android:exported="true">
    <intent-filter>
      <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
    </intent-filter>
  </activity>

  <!-- For versions starting Android 14, create an activity alias to show the rationale
       of Health Connect permissions once users click the privacy policy link. -->

  <activity-alias
      android:name="ViewPermissionUsageActivity"
      android:exported="true"
      android:targetActivity=".PermissionsRationaleActivity"
      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>  
  ...  
</application>

Request Permissions

Before reading or subscribing to data from Health Connect the end user must grant permissions for each Health Connect Record Type.

Get previously granted permissions

Checking the permission status for a Health Connect Record Type will indicate if it is possible to read and subscribe to data changes for a Health Connect Record.

Health Connect permissions are documented in Google's guide.

For more details on how to check for previously granted permissions, please refer to the Native Android Inform SDK documentation on Permissions.

Request new permissions

Health Connect permissions are documented in Google's guide.

For more details on how to request new permissions, please refer to the Native Android Inform SDK documentation on Permissions.


Managing Subscriptions

To subscribe to data updates from Health Connect, please refer to the Native Android Inform SDK documentation on Managing Subscriptions.


Currently Supported Data Types

For details on the supported data types for Health Connect, please refer to the Native Android Inform SDK documentation on Data Types.


Fetching Historical Data

The Health Connect integration supports retrieving 30 days of historical step data. For details on the historical fetch for Health Connect, please refer to the Native Android Inform SDK documentation on Historical Fetch.


Logout

To remove all subscriptions and log an end user out of Health Connect, simply call disconnect.


Health Connect Exceptions

For details on the handling exceptions for Health Connect, please refer to the Native Android Inform SDK documentation on Listening to Health Connect Exceptions.