> ## Documentation Index
> Fetch the complete documentation index at: https://docs.junction.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Android Health Connect

> Integrate Android Health Connect as an SDK-based provider with Junction, including setup, permissions, and required Mobile SDK components.

Android Health Connect is an SDK-based provider. Your Android consumer app would embed the Junction Mobile SDKs on a supported
stack. Data are then pulled from the Health Connect data store on the user's Android device.

Refer to the [Mobile SDK Installation](/wearables/sdks/installation) and [Junction Health SDK](/wearables/sdks/health/overview) guides for SDK installation
instructions and general API usage. This guide contains information on the behavior and required configuration
specific to the Android Health Connect integration.

<Card title="Mobile SDK Installation" icon="helmet-safety" href="/wearables/sdks/installation" horizontal>
  Learn about the minimum runtime and build-time requirements of Junction Mobile SDKs, and how to add them into
  your project through your package dependency manager.
</Card>

<Card title="Junction Health SDK" icon="heart" iconType="solid" href="/wearables/sdks/health/overview" horizontal>
  Learn about the initial setup required by Junction Health SDK, and the API exposed by Junction Health SDK
  for managing and inspecting health data permissions and automatic data sync.
</Card>

## Getting Started

To enable this integration, you would need to integrate [Junction Core SDK](/wearables/sdks/vital-core) and
[Junction Health SDK](/wearables/sdks/health/overview) into your Native Android, React Native or Flutter mobile app.

<Steps>
  <Step title="Add Junction SDKs as dependencies">
    Review the [installation requirements and package installation instructions](/wearables/sdks/installation).
  </Step>

  <Step title="Integrate with Junction Mobile SDK Authentication">
    Follow the [SDK Authentication](/wearables/sdks/authentication) guidance to integrate your app with the authentication
    mechanism of Junction Core SDK.
  </Step>

  <Step title="Configure Health SDK and ask user for read permissions">
    Follow the [Junction Health SDK](/wearables/sdks/health/overview) starting guidance to
    [configure the Health SDK](/wearables/sdks/health/overview#configure-the-junction-health-sdk) and to
    [ask for health data read permissions](/wearables/sdks/health/overview#ask-user-for-health-data-permissions) from your user.

    <Note>
      Health data sync is activated only on `VitalResource`s for which you have asked your user for permissions. If you
      did not ask for permissions, data sync would not occur.
    </Note>
  </Step>

  <Step title="[Optional] Customize the Foreground Service notification">
    Follow the [Running as Foreground Service](#running-as-foreground-service) guidance below to
    customize the Foreground Service notification which may be shown by the Android OS during
    any prolonged health data sync attempts.
  </Step>

  <Step title="[Optional] Configure Background Sync">
    Follow the [Background Sync](#background-sync) guidance below to
    configure regular background sync.
  </Step>
</Steps>

## Review the Google Play Store policy

Apps using Android Health Connect **require prior Google approval** before they can be released on Google Play Store.

Check out the official [Google Play Store policy on Android Health Connect](https://support.google.com/googleplay/android-developer/answer/12991134?hl=en-GB).
Note that the application form is located under the "How do I access data through Health Connect?" section.

## Configure your AndroidManifest.xml

### Health Connect privacy dialog

<Warning>Missing manifest declarations may result in Health Connect ignoring your app.</Warning>

Check [the Health Connect Getting Started guide](https://developer.android.com/health-and-fitness/guides/health-connect/develop/get-started#show-privacy-policy) for the official requirements.

Here is a minimum declaration example:

```xml theme={null}
<manifest ...>
    <application ...>
        <!-- BEGIN: Mandatory for Health Connect permission flow (Android 13 or below) -->
        <!-- Must either be your MainActivity, or a separate Activity; cannot be an activity-alias. -->
        <activity android:name=".MainActivity" ...>
            <intent-filter>
                <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
            </intent-filter>
        </activity>
        <!-- END -->

        <!-- BEGIN: Mandatory for Health Connect permission flow (Android 14 or above) -->
        <!-- Can be an activity or an activity-alias. -->
        <activity-alias
            android:name="ViewPermissionUsageActivity"
            android:exported="true"
            android:targetActivity=".MainActivity"
            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>
        <!-- END -->
    </application>

    <queries>
        <package android:name="com.google.android.apps.healthdata" />
    </queries>
</manifest>
```

### Health Connect permissions

Your app manifest (`AndroidManifest.xml`) must declare all the read or write permissions for all the data types you intend to sync.

For example, if you intend to sync Blood Pressure records and Blood Glucose records, your app manifest must contain the following
`<uses-permission>` declarations:

```xml theme={null}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <!-- ... other declarations -->

    <!-- BEGIN: Health Connect permissions -->
    <uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE" />
    <uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE" />
    <!-- END: Health Connect permissions -->
</manifest>
```

| SDK `VitalResource` type | Read permissions required                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `Profile`                | `android.permission.health.READ_HEIGHT`                                                                                                                                                                                                                                                                                                                                                                      |
| `Body`                   | `android.permission.health.READ_BODY_FAT`<br />`android.permission.health.READ_WEIGHT`                                                                                                                                                                                                                                                                                                                       |
| `Workout`                | `android.permission.health.READ_EXERCISE`<br />`android.permission.health.READ_HEART_RATE`<br />`android.permission.health.READ_RESPIRATORY_RATE`<br />`android.permission.health.READ_DISTANCE`<br />`android.permission.health.READ_ACTIVE_CALORIES_BURNED`<br />`android.permission.health.READ_ELEVATION_GAINED`<br />`android.permission.health.READ_POWER`<br />`android.permission.health.READ_SPEED` |
| `Activity`               | `android.permission.health.READ_ACTIVE_CALORIES_BURNED`<br />`android.permission.health.READ_BASAL_METABOLIC_RATE`<br />`android.permission.health.READ_TOTAL_CALORIES_BURNED`<br />`android.permission.health.READ_DISTANCE`<br />`android.permission.health.READ_STEPS`<br />`android.permission.health.READ_FLOORS_CLIMBED`<br />`android.permission.health.READ_VO2_MAX`                                 |
| `Sleep`                  | `android.permission.health.READ_SLEEP`<br />`android.permission.health.READ_HEART_RATE`<br />`android.permission.health.READ_RESPIRATORY_RATE`<br />`android.permission.health.READ_HEART_RATE_VARIABILITY`<br />`android.permission.health.READ_OXYGEN_SATURATION`<br />`android.permission.health.READ_RESTING_HEART_RATE`                                                                                 |
| `Glucose`                | `android.permission.health.READ_BLOOD_GLUCOSE`                                                                                                                                                                                                                                                                                                                                                               |
| `BloodPressure`          | `android.permission.health.READ_BLOOD_PRESSURE`                                                                                                                                                                                                                                                                                                                                                              |
| `HeartRate`              | `android.permission.health.READ_HEART_RATE`                                                                                                                                                                                                                                                                                                                                                                  |
| `Steps`                  | `android.permission.health.READ_STEPS`                                                                                                                                                                                                                                                                                                                                                                       |
| `ActiveEnergyBurned`     | `android.permission.health.READ_ACTIVE_CALORIES_BURNED`                                                                                                                                                                                                                                                                                                                                                      |
| `BasalEnergyBurned`      | `android.permission.health.READ_ACTIVE_CALORIES_BURNED`<br />`android.permission.health.READ_BASAL_METABOLIC_RATE`<br />`android.permission.health.READ_TOTAL_CALORIES_BURNED`                                                                                                                                                                                                                               |
| `Water`                  | `android.permission.health.READ_HYDRATION`                                                                                                                                                                                                                                                                                                                                                                   |

### Foreground Service permissions

Junction Health SDK runs all its data sync workers inside short-service Foreground Services.

At build time, Junction Health SDK injects all the required `shortService` Foreground Services declarations
into your AndroidManifest.xml. You need not modify your app's Manifest to enable this.

<Info>
  Junction Health SDK can run work inside the [AndroidX WorkManager](https://developer.android.com/develop/background-work/background-tasks/persistent/how-to/long-running#declare-foreground-service-types-manifest)
  foreground service, as well as our own `SyncOnExactAlarmService`. The merged AndroidManifest.xml of your app
  would include both of them.
</Info>

## Prepare your app architecture

<Warning>Non-compliance with the guidelines below may result in Health Connect permission flow failing to launch on specific Android OS versions.</Warning>

<Tabs>
  <Tab title="Native Android">
    When requesting permission using the `ActivityResultContract` created by Junction Health `createPermissionRequestContract()`, you must launch
    the contract using AndroidX Activity Result API.

    Attempts to launch the contract manually via the legacy `Activity.startActivityForResult` API would result in an `android.content.ActivityNotFoundException`
    exception on Android 14 and later.
  </Tab>

  <Tab title="React Native">
    The `MainActivity` of your Android host app project must be augmented with either of the two options below:

    1. Subclassing `VitalHealthReactActivity` provided by the Junction Health SDK `com.vitalhealthreactnative` package, instead of the default `ReactActivity`.

    2. Overriding `onRequestPermissionsResult(...)` so as to manually propagate permission request results to the Junction Health SDK.

    ```kotlin theme={null}
    // MainActivity in your host app project
    open class MainActivity: ReactActivity() {
      override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
      ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)

        // Propagate permission flow results to Junction Health SDK.
        VitalHealthReactNativeModule.onRequestPermissionsResult(
          this.reactInstanceManager,
          requestCode,
          permissions,
          grantResults
        )
      }
    }
    ```

    The augmentation above is a workaround to React Native's AndroidX-incompatible handling of permission request result callbacks,
    which breaks the AndroidX Activity Result API required by Android Health Connect.
  </Tab>

  <Tab title="Flutter">
    The `MainActivity` of your Android host app project must subclass `FlutterFragmentActivity` instead of `FlutterActivity`.

    This is because `FlutterFragmentActivity` is AndroidX compatible and therefore supports the Activity Result API as required by
    Android Health Connect, whilst `FlutterActivity` is not.
  </Tab>
</Tabs>

## Synchronization

### Sync On App Launch

When your app resumes from background (i.e., having no Activity), Junction Health SDK triggers a data sync on all the resources
to which the user has granted read permission.

The SDK imposes a **2-minute** throttle on automatic data sync. This is to prevent rapid app switching from causing an
excessive amount of data sync work being scheduled.

<Info>
  Junction Health SDK relies on the [AndroidX ProcessLifecycleOwner](https://developer.android.com/reference/androidx/lifecycle/ProcessLifecycleOwner)
  to get notified of your app's resumption.
</Info>

### Running as Foreground Service

<Info>You cannot opt-out of this behavior.</Info>

Junction Health SDK runs all its data sync workers inside a Foreground Service. Running as a foreground service helps in two ways:

1. It ensures ongoing data sync can run to completion even if the user switches away from your app; and

2. data sync workers have to be **in foreground** to read data from Health Connect. Health Connect prohibits
   reading data from background.

Android requires every Foreground Service to [be associated with a user-visible notification](https://developer.android.com/develop/background-work/services/foreground-services#user-dismiss-notification).
The OS typically grants a grace period of about 10 seconds before making the user aware of this notification. In other words,
if the data sync worker completes within the grace period, no notification would be posted.

Junction Health SDK installs these notification copies by default:

| Item                 | Copy                                                             |
| -------------------- | ---------------------------------------------------------------- |
| Notification Title   | Health Data Sync                                                 |
| Notification Content | `{APP_NAME}` is synchronizing with Health Connect...             |
| Channel Title        | Health Data Sync                                                 |
| Channel Description  | Notifies when `{APP_NAME}` is synchronizing with Health Connect. |

You can customize it in two ways:

<Tabs>
  <Tab title="Native Android">
    Register your custom `SyncNotificationBuilder` through `VitalHealthConnectManager.syncNotificationBuilder`.

    You should register it as soon as your app process is created. One way to ensure this is through the AndroidX Startup
    library. You can define an `Initializer` of your own that depends on the SDK `VitalHealthConnectInitializer`.

    #### An example App Startup Initializer implementation

    ```kotlin theme={null}
    package com.example.app

    import android.content.Context
    import androidx.startup.Initializer
    import io.tryvital.vitalhealthconnect.VitalHealthConnectManager
    import io.tryvital.vitalhealthconnect.VitalHealthConnectInitializer

    class ExampleSyncNotificationBuilderInitializer: Initializer<Unit> {
        override fun create(context: Context) {
            val manager = VitalHealthConnectManager.getOrCreate(context)
            manager.syncNotificationBuilder = ExampleSyncNotificationBuilder
        }

        override fun dependencies(): MutableList<Class<out Initializer<*>>> = mutableListOf(
            VitalHealthConnectInitializer::class.java,
        )
    }
    ```

    #### An example `SyncNotificationBuilder` implementation

    ```kotlin theme={null}
    package io.tryvital.sample

    import android.app.Notification
    import android.app.NotificationChannel
    import android.app.NotificationManager
    import android.content.Context
    import android.content.Context.NOTIFICATION_SERVICE
    import androidx.core.app.NotificationCompat
    import io.tryvital.vitalhealthconnect.SyncNotificationBuilder
    import io.tryvital.vitalhealthconnect.model.VitalResource

    object ExampleSyncNotificationBuilder: SyncNotificationBuilder {
        override fun build(context: Context, resources: Set<VitalResource>): Notification {
            return NotificationCompat.Builder(context, createChannel(context))
                .setContentTitle("Example Sync")
                .setContentText("Syncing your data")
                .setOngoing(true)
                .setSmallIcon(android.R.drawable.ic_popup_sync)
                .build()
        }

        fun createChannel(context: Context): String {
            val importance = NotificationManager.IMPORTANCE_MIN
            val mChannel = NotificationChannel("ExampleSyncNotification", "Example Sync", importance)
            mChannel.description = "Notifies when Example is syncing your data"
            val notificationManager = context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
            notificationManager.createNotificationChannel(mChannel)
            return mChannel.id
        }
    }
    ```
  </Tab>

  <Tab title="React Native">
    Register your custom copies through `VitalHealth.setSyncNotificationContent` as early as possible in
    your React Native root component.

    ```typescript theme={null}
    import { VitalHealth } from '@tryvital/vital-health-react-native';

    await VitalHealth.setSyncNotificationContent({
        "notificationTitle": "Example Sync",
        "notificationContent": "Syncing your data",
        "channelName": "Example Sync",
        "channelDescription": "Notifies when Example is syncing your data"
    });
    ```
  </Tab>

  <Tab title="Flutter">
    Register your custom copies through `vital_health.setSyncNotificationContent` as early as possible in
    your Flutter app startup logic.

    ```dart theme={null}
    import 'package:vital_health/vital_health.dart' as vital_health;

    vital_health.setSyncNotificationContent(vital_health.SyncNotificationContent(
        "Example Sync",
        "Syncing your data",
        "Example Sync",
        "Notifies when Example is syncing your data"));
    ```
  </Tab>
</Tabs>

## Background Sync

Junction Health SDK supports an **opt-in** Android Background Sync feature. It provides a continuous monitoring
experience with Android Health Connect, similar to [Background Delivery for Apple HealthKit](/wearables/guides/apple-healthkit#setting-up-apple-healthkit-background-delivery) on iOS.

### Sync Frequency

The [Sync On App Launch](#sync-on-app-launch) behavior is always-on.

When Background Sync is enabled, the SDK additionally schedules hourly sync using the Android [Exact Alarms](https://developer.android.com/develop/background-work/services/alarms/schedule) mechanism.

The OS has full discretion on whether to honor or defer the time as scheduled by the Junction Health SDK. This includes the policies
of the base Android OS, as well as any vendor-specific OS augmentation.

For example, the device may enter [Doze mode](https://developer.android.com/training/monitoring-device-state/doze-standby) during device inactivity. Doze mode
would batch and defer most Exact Alarms and other background work to run at a lower frequency.

<Info>
  Not to be confused with Alarm Clock apps, **Exact Alarm** is the technical name of an Android framework for scheduling
  app wake-ups in background at certain wall clock time. It is the Junction Health SDK being silently "alarmed" in background.

  Your user **will not be alarmed hourly** as a result of enabling Background Sync.

  However, if the data sync took longer than 10 seconds, the OS might notify them of this occurrence with a user-visible notification.
  The notification content is configurable by you — see the ["Running as Foreground Service"](#running-as-foreground-service) section for more details.
</Info>

### Runtime Permission Request

Since Android 12 (API Level 31), scheduling Exact Alarm (`SCHEDULE_EXACT_ALARM`) requires a runtime permission request from the user.
More specifically:

1. The user must go through an interactive flow to grant the *"Alarms & Reminders"* permission.
   * This flow is also reachable through the *"Alarms & Reminders"* section in Android Settings.
2. The user may refuse to grant the *"Alarms & Reminders"* permission.
3. The user may revoke the *"Alarms & Reminders"* permission through Android Settings at any time.

Since Android 13 (API Level 33), a new mutually exclusive `USE_EXACT_ALARM` permission was introduced. This permits your app to
schedule Exact Alarms without interactive permission requests.

<Warning>
  `USE_EXACT_ALARM` attracts scrutiny during Google Play Store review. Per the Google Play [Exact alarm permission policy](https://support.google.com/googleplay/android-developer/answer/9888170?hl=en-GB):

  > USE\_EXACT\_ALARM is a restricted permission and apps must only declare this permission if their core functionality supports
  > the need for an exact alarm. Apps that request this restricted permission are subject to review, and those that do not meet
  > the acceptable use case criteria will be disallowed from publishing on Google Play.
  >
  > *(excerpted on 20 March 2024)*

  If you choose to incorporate `USE_EXACT_ALARM`, you should prepare to justify to Google Play Store:

  1. Why hourly background sync is essential to your product experience; and
  2. Why the interactive permission request required by `SCHEDULE_EXACT_ALARM` is suboptimal for your product experience.
</Warning>

Here is a matrix summarizing the Exact Alarm permission request requirements:

| Android OS           | API Level | Requirements                                                                                                                                                                    |
| -------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Android 11 or below  | \<=30     | No interactive permission request.                                                                                                                                              |
| Android 12           | 31, 32    | `SCHEDULE_EXACT_ALARM`: Requires a runtime permission request. Revocable.                                                                                                       |
| Android 13 and above | >=33      | App must declare either:<ul><li>`SCHEDULE_EXACT_ALARM`: Requires runtime permission request. Revocable.</li><li>`USE_EXACT_ALARM`: No interactive permission request.</li></ul> |

### Updating your AndroidManifest.xml

Your app's AndroidManifest.xml must include the following `uses-permission` claims:

<Tabs>
  <Tab title="The SCHEDULE_EXACT_ALARM route">
    <Note>
      Make sure you read and understand [Runtime Permission Request](#runtime-permission-request) before moving forward.
      This option is mutually exclusive with `USE_EXACT_ALARM` in the second tab.
    </Note>

    ```xml theme={null}
    <?xml version="1.0" encoding="utf-8"?>
    <manifest ...>

        <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />

    </manifest>
    ```
  </Tab>

  <Tab title="The USE_EXACT_ALARM route">
    <Warning>
      Make sure you read and understand [Runtime Permission Request](#runtime-permission-request) before moving forward,
      especially the Google Play Store review policy surrounding the `USE_EXACT_ALARM` permission.
      This option is mutually exclusive with `SCHEDULE_EXACT_ALARM` in the first tab.
    </Warning>

    ```xml theme={null}
    <?xml version="1.0" encoding="utf-8"?>
    <manifest ...>

        <uses-permission android:name="android.permission.USE_EXACT_ALARM" android:minSdkVersion="33" />

        <!-- Fallback to SCHEDULE_EXACT_ALARM on API Level 31-32 -->
        <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />

    </manifest>
    ```
  </Tab>
</Tabs>

### Enabling Background Sync

<Tabs>
  <Tab title="Native Android">
    You can enable Background Sync through `enableBackgroundSyncContract()` (an AndroidX `ActivityResultContract`).

    If the runtime [requires an interactive permission request](#runtime-permission-request), this contract will launch
    an Android Intent to request the *"Alarms & Reminders"* permission. The contract result is a boolean, indicating whether
    or not the Background Sync has been enabled successfully. For example, if the user did not grant the permission during the said Android Intent,
    the contract returns `false`.

    Otherwise, the contract returns `true` synchronously when no user interaction is required.

    You must launch this `ActivityResultContract` either through the in-built Android Compose support, or
    through the AndroidX Activity Result API if you do not use Android Compose.

    You can also inspect if Background Sync has been enabled through the `isBackgroundSyncEnabled` property.

    <CodeGroup>
      ```kotlin Android Compose theme={null}
      import androidx.activity.compose.rememberLauncherForActivityResult
      import androidx.compose.runtime.rememberCoroutineScope
      import androidx.compose.material3.*
      import io.tryvital.vitalhealthconnect.VitalHealthConnectManager

      val manager: VitalHealthConnectManager = ...

      val permissionsLauncher = rememberLauncherForActivityResult(
          manager.enableBackgroundSyncContract()
      ) { success ->
          Log.i("VitalBackgroundSync", "Enabled? $success")

          val enabled = manager.isBackgroundSyncEnabled
          Log.i("VitalBackgroundSync", "Enabled? $enabled")
      }

      Button(onClick = { permissionsLauncher.launch(Unit) }) {
          Text("Enable Background Sync")
      }
      ```

      ```kotlin AndroidX Activity Result API theme={null}
      import androidx.activity.ComponentActivity
      import io.tryvital.vitalhealthconnect.VitalHealthConnectManager

      val activity: ComponentActivity = ...
      val manager: VitalHealthConnectManager = ...

      activity.registerForActivityResult(contract) { success ->
          Log.i("VitalBackgroundSync", "Enabled? $success")

          val enabled = manager.isBackgroundSyncEnabled
          Log.i("VitalBackgroundSync", "Enabled? $enabled")
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="React Native">
    You can enable Background Sync through `enableBackgroundSync()`.

    If the runtime [requires an interactive permission request](#runtime-permission-request),
    `enableBackgroundSync()` will launch an Android Intent to request the *"Alarms & Reminders"* permission.
    The promise result is a boolean, indicating whether or not the Background Sync has been enabled successfully.
    For example, if the user did not grant the permission during the said Android Intent, the contract returns `false`.

    Otherwise, `enableBackgroundSync()` returns `true` immediately when no user interaction is required.

    You can also inspect if Background Sync has been enabled through the `isBackgroundSyncEnabled` property.

    <Note>
      When running on iOS, both `enableBackgroundSync()` and `isBackgroundSyncEnabled` always return `true` immediately.
    </Note>

    ```typescript theme={null}
    import { VitalHealth } from "@tryvital/vital-health-react-native";

    const success = await VitalHealth.enableBackgroundSync();
    console.log("background sync enabled?", success);

    const enabled = await VitalHealth.isBackgroundSyncEnabled;
    console.log("background sync enabled?", enabled);
    ```
  </Tab>

  <Tab title="Flutter">
    You can enable Background Sync through `enableBackgroundSync()`.

    If the runtime [requires an interactive permission request](#runtime-permission-request),
    `enableBackgroundSync()` will launch an Android Intent to request the *"Alarms & Reminders"* permission.
    The promise result is a boolean, indicating whether or not the Background Sync has been enabled successfully.
    For example, if the user did not grant the permission during the said Android Intent, the contract returns `false`.

    Otherwise, `enableBackgroundSync()` returns `true` immediately when no user interaction is required.

    You can also inspect if Background Sync has been enabled through the `isBackgroundSyncEnabled` property.

    <Note>
      When running on iOS, both `enableBackgroundSync()` and `isBackgroundSyncEnabled` always return `true` immediately.
    </Note>

    ```dart theme={null}
    import 'package:vital_health/vital_health.dart' as vital_health;

    final success = await vital_health.enableBackgroundSync();
    log("background sync enabled? ${success}")

    final enabled = await vital_health.isBackgroundSyncEnabled;
    log("background sync enabled? ${enabled}")
    ```
  </Tab>
</Tabs>

### Disabling Background Sync

<Tabs>
  <Tab title="Native Android">
    You can disable Background Sync through the `disableBackgroundSync()` method.

    You can also inspect if Background Sync has been disabled through the `isBackgroundSyncEnabled` property.

    ```kotlin theme={null}
    import io.tryvital.vitalhealthconnect.VitalHealthConnectManager

    val manager: VitalHealthConnectManager = ...
    manager.disableBackgroundSync()

    val enabled = manager.isBackgroundSyncEnabled
    Log.i("VitalBackgroundSync", "Enabled? $enabled")
    ```
  </Tab>

  <Tab title="React Native">
    You can disable Background Sync through the `disableBackgroundSync()` method.

    You can also inspect if Background Sync has been disabled through the `isBackgroundSyncEnabled` property.

    <Note>
      When running on iOS, this API **is a no-op**. HealthKit Background Delivery is always-on
      on iOS.
    </Note>

    ```typescript theme={null}
    import { VitalHealth } from "@tryvital/vital-health-react-native";

    await VitalHealth.disableBackgroundSync();

    const enabled = await VitalHealth.isBackgroundSyncEnabled;
    console.log("background sync enabled?", enabled);
    ```
  </Tab>

  <Tab title="Flutter">
    You can disable Background Sync through the `disableBackgroundSync()` method.

    You can also inspect if Background Sync has been disabled through the `isBackgroundSyncEnabled` property.

    <Note>
      When running on iOS, this API **is a no-op**. HealthKit Background Delivery is always-on
      on iOS.
    </Note>

    ```dart theme={null}
    import 'package:vital_health/vital_health.dart' as vital_health;

    await vital_health.disableBackgroundSync();

    final enabled = await vital_health.isBackgroundSyncEnabled;
    log("background sync enabled? ${enabled}")
    ```
  </Tab>
</Tabs>

### Miscellaneous

When you `signOut()` a user, Junction SDK will automatically disable Background Sync.
