You are reading the docs for Health13.x, an older version. Go to 14.x, the latest version.
Health Connect
Check, install and update Google Health Connect, and request historical and background data access on Android.
Copy MarkdownOpen inOpen in GitHubView as MarkdownOpen in Scira AIOpen in ChatGPTOpen in ClaudeOpen in Cursor
Google Health Connect is Android's centralized health data repository. Unlike HealthKit, which is built into iOS, Health Connect is part of Android only on Android 14 and later. On Android 9 to 13, the user installs the Health Connect app from Google Play, and older Android versions cannot use Health Connect.
The plugin provides APIs to check its availability, request its installation, and manage Health Connect permissions.
Method
Returns
Purpose
getHealthConnectSdkStatus()
Future<HealthConnectSdkStatus?>
Get the Health Connect SDK status.
isHealthConnectAvailable()
Future<bool>
Check whether Health Connect is installed and ready.
installHealthConnect()
Future<void>
Open the app store to install or update Health Connect.
isHealthDataHistoryAvailable()
Future<bool>
Check whether the device supports historical data access.
isHealthDataHistoryAuthorized()
Future<bool>
Check whether historical data access is granted.
requestHealthDataHistoryAuthorization()
Future<bool>
Request access to historical data.
isHealthDataInBackgroundAvailable()
Future<bool>
Check whether background data access is supported.
It returns a HealthConnectSdkStatus value, or null on iOS and on error:
Status
Value
Description
sdkAvailable
3
Health Connect is installed and ready.
sdkUnavailableProviderUpdateRequired
2
Android 9 to 13 only: the Health Connect app is missing, disabled or too old. Offer installHealthConnect().
sdkUnavailable
1
Health Connect cannot be used on this device. Below Android 9, this is always the case. On Android 14 and later, the cause is a work profile or another profile, or a system without the Health Connect service. Hide the Health Connect features.
final status = await health.getHealthConnectSdkStatus();switch (status) { case HealthConnectSdkStatus.sdkAvailable: print('Health Connect is ready'); break; case HealthConnectSdkStatus.sdkUnavailableProviderUpdateRequired: print('Install or update Health Connect'); break; case HealthConnectSdkStatus.sdkUnavailable: print('Health Connect cannot be used on this device'); break; case null: print('Error checking status');}
The plugin caches the last status in health.healthConnectSdkStatus. Until the first check, and always on iOS, it is sdkUnavailable.
On Android, isHealthConnectAvailable() also refreshes it, and so do the methods that check availability first, such as requestAuthorization() and getHealthDataFromTypes(). Call getHealthConnectSdkStatus() again to refresh it:
isHealthConnectAvailable() is a boolean check for Health Connect.
Future<bool> isHealthConnectAvailable()
It returns true when Health Connect is installed and ready, and false when it is unavailable or needs an update. On iOS, it always returns true. On Android, the call also updates healthConnectSdkStatus, which tells whether installing Health Connect helps:
bool available = await health.isHealthConnectAvailable();if (!available && health.healthConnectSdkStatus == HealthConnectSdkStatus.sdkUnavailableProviderUpdateRequired) { // Prompt user to install _showHealthConnectInstallDialog();}
Always check availability before any health operation:
Future<void> ensureHealthConnectReady() async { if (!await health.isHealthConnectAvailable()) { throw HealthException( null, 'Health Connect is not available. Please install it first.', ); }}Future<void> fetchHealthData() async { await ensureHealthConnectReady(); // Now safe to proceed final data = await health.getHealthDataFromTypes(...);}
Explain Health Connect in a dialog, then open the store if the user agrees:
Future<void> setupHealthConnect() async { // Check whether Health Connect is missing or too old final status = await health.getHealthConnectSdkStatus(); if (status == HealthConnectSdkStatus.sdkUnavailableProviderUpdateRequired) { // Show dialog explaining Health Connect final shouldInstall = await showDialog<bool>( context: context, builder: (context) => AlertDialog( title: Text('Install Health Connect'), content: Text( 'This app requires Health Connect to access health data. ' 'Would you like to install it now?', ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(false), child: Text('Cancel'), ), TextButton( onPressed: () => Navigator.of(context).pop(true), child: Text('Install'), ), ], ), ); if (shouldInstall == true) { await health.installHealthConnect(); } }}
Offer the install only when Health Connect is missing or too old, and tell the user when it cannot be used:
Future<void> handleHealthConnectStatus() async { final status = await health.getHealthConnectSdkStatus(); switch (status) { case HealthConnectSdkStatus.sdkAvailable: // Ready to use break; case HealthConnectSdkStatus.sdkUnavailableProviderUpdateRequired: // Need installation or update showDialog( context: context, builder: (context) => AlertDialog( title: Text('Health Connect Required'), content: Text('Please install or update Health Connect to continue.'), actions: [ TextButton( onPressed: () { health.installHealthConnect(); Navigator.pop(context); }, child: Text('Install'), ), ], ), ); break; case HealthConnectSdkStatus.sdkUnavailable: case null: // Cannot be used on this device, or the check failed showDialog( context: context, builder: (context) => AlertDialog( title: Text('Health Connect Unavailable'), content: Text('Health Connect is not available on this device.'), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: Text('OK'), ), ], ), ); break; }}
By default, Health Connect lets an app read data from up to 30 days before the user first granted it a permission. To read older data, the user must also grant historical data access.
The manifest baseline in Android setup declares the optional READ_HEALTH_DATA_HISTORY permission for historic reading. All three methods return Future<bool>:
Method
Returns true
Returns false
isHealthDataHistoryAvailable()
The device supports the historical data permission.
The feature is not available (older devices or SDK).
isHealthDataHistoryAuthorized()
Historical data access is granted.
Access is not granted, or the feature is unavailable.
requestHealthDataHistoryAuthorization()
Permission is granted.
Permission is denied, or an error occurred.
On iOS, isHealthDataHistoryAvailable() returns false, and the other two methods return true. On Android, requestHealthDataHistoryAuthorization() throws an UnsupportedError when Health Connect is not available.
Check whether the device supports historical data access:
bool historyAvailable = await health.isHealthDataHistoryAvailable();if (historyAvailable) { print('Can request historical data access');} else { print('Historical data not supported on this device');}
With historical access granted, you can fetch data from any time period:
Future<void> fetchLongTermData() async { // Ensure historical access final hasHistoricalAccess = await health.isHealthDataHistoryAuthorized(); if (!hasHistoricalAccess) { final granted = await health.requestHealthDataHistoryAuthorization(); if (!granted) { throw Exception('Historical data access required for this feature'); } } // Now can fetch data from any time period final data = await health.getHealthDataFromTypes( types: [HealthDataType.WEIGHT], startTime: DateTime.now().subtract(Duration(days: 365)), // 1 year ago endTime: DateTime.now(), ); print('Fetched ${data.length} historical data points');}
Health Connect supports reading health data in the background. The manifest baseline in Android setup declares the optional READ_HEALTH_DATA_IN_BACKGROUND permission for background reading. All three methods return Future<bool>:
Method
Returns true
Returns false
isHealthDataInBackgroundAvailable()
The background access feature is available.
The feature is not supported.
isHealthDataInBackgroundAuthorized()
Background access is granted.
Access is not granted, or the feature is unavailable.
requestHealthDataInBackgroundAuthorization()
Permission is granted.
Permission is denied, or an error occurred.
On iOS, isHealthDataInBackgroundAvailable() returns false, and the other two methods return true. On Android, requestHealthDataInBackgroundAuthorization() throws an UnsupportedError when Health Connect is not available.
Register a periodic background task with WorkManager or a similar scheduler once background access is granted:
Future<void> initializeHealthSync() async { // Request background permission final hasBackgroundAccess = await health.isHealthDataInBackgroundAuthorized(); if (!hasBackgroundAccess) { final granted = await health.requestHealthDataInBackgroundAuthorization(); if (!granted) { print('Background sync not available - using foreground only'); return; } } // Setup WorkManager or similar for background tasks Workmanager().registerPeriodicTask( 'health-sync', 'syncHealthData', frequency: Duration(hours: 1), );}