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

# Health Bridge

> Read health data such as steps, heart rate, calories, and sleep from Apple HealthKit and Google Health Connect with the Health Bridge plugin.

Health Bridge provides a unified interface to access and sync health data from users' devices using **Apple HealthKit** (iOS) and **Google Health Connect** (Android). The plugin enables you to fetch health metrics such as steps, heart rate, calories, and sleep data, so you can build wellness and fitness features in your app.

> [!TIP]
>
> **Test  with our demo page**
>
> We host a ready-made demo page at
>
> that calls the  features through the Median JavaScript Bridge.
> Load it inside your Median app during development, either by setting it
> as your app's website URL in App Studio or by navigating to it from your
> own site, and use it to confirm  works on a real device before
> you add it to your own pages.
>
> The demo page only works inside a Median app with  enabled.
> Opened in a regular mobile or desktop browser, the native features
> won't respond. Remember to switch your app back to your own URL before
> release.

## Why use Health Bridge?

Health Bridge takes care of handling platform-specific details like permissions, data sources, and user consent, so you can focus on delivering value to your users. The plugin abstracts away the complexity of working with different health platforms while maintaining full access to rich health data.

* **Unified interface**: Single API that works across iOS (Apple HealthKit) and Android (Google Health Connect)
* **Platform handling**: Automatically manages platform-specific permissions, data sources, and user consent flows
* **Wellness features**: Access comprehensive health metrics including steps, heart rate, calories, sleep, and more
* **Data accessibility**: Retrieve historical health data with flexible date ranges and grouping options

## Before you start

**Prerequisites**

* [ ] A Median app with the JavaScript Bridge enabled
* [ ] The plugin activated in your app

## Key concepts

The following concepts will help you implement Health Bridge:

**Quick reference**: Health Bridge supports 6 main categories of health data to help you build comprehensive wellness features:

* **Activity** - Track physical movement and exercise metrics (steps, distance, calories, exercise time)
* **Body measurements** - Monitor physical characteristics and body composition (height, weight, BMI, body fat, temperature)
* **Cycle tracking** - Access menstrual cycle data for reproductive health monitoring
* **Nutrition** - Track dietary intake and hydration (calorie intake, water intake, nutrition data)
* **Sleep** - Monitor sleep patterns and duration for recovery and wellness insights
* **Vitals** - Access critical health indicators (heart rate, blood pressure, oxygen saturation, glucose)

**Supported data types**: Health Bridge supports health metrics organized by category, all returned in **metric units only**. Expand each category below to view the complete metric details:

> [accordion] Activity features
>
> | Data type | Description | Unit |
> | - | - | - |
> | `steps` | Number of steps taken | count |
> | `distance` | Distance walked or run | meters (m) |
> | `activeEnergy` | Active calories burned | kilocalories (kcal) |
> | `totalCaloriesBurned` | Total calories burned | kilocalories (kcal) |
> | `exerciseTime` | Time spent exercising | minutes (min) |
> | `elevationGain` | Elevation gain | meters (m) |
> | `speed` | Speed | meters per second (m/s) |

> [accordion] Body measurements
>
> | Data type | Description | Unit |
> | - | - | - |
> | `height` | User's height | meters (m) |
> | `weight` | User's weight | kilograms (kg) |
> | `bmi` | Body mass index | unitless |
> | `bodyFat` | Body fat | percent (%) |
> | `bodyTemperature` | Body temperature | degrees Celsius (°C) |

> [accordion] Cycle tracking
>
> | Data type | Description | Unit |
> | - | - | - |
> | `menstruation` | Menstruation | — |

> [accordion] Nutrition
>
> | Data type | Description | Unit |
> | - | - | - |
> | `calorieIntake` | Dietary calorie intake | kilocalories (kcal) |
> | `waterIntake` | Water consumed | milliliters (ml) |
> | `nutrition` | Nutrition | — |

> [accordion] Sleep
>
> | Data type | Description | Unit |
> | - | - | - |
> | `sleep` | Sleep duration | minutes (min) |

> [accordion] Vitals
>
> | Data type | Description | Unit |
> | - | - | - |
> | `heartRate` | Heart rate | beats per minute (bpm) |
> | `restingHeartRate` | Resting heart rate | beats per minute (bpm) |
> | `heartRateVariability` | Heart rate variability | milliseconds (ms) |
> | `bloodPressure` | Blood pressure | millimeters of mercury (mmHg) |
> | `bloodGlucose` | Blood glucose | millimoles per liter (mmol/L) |
> | `oxygenSaturation` | Oxygen saturation | percent (%) |
> | `bodyTemperature` | Body temperature | degrees Celsius (°C) |
> | `respiratoryRate` | Respiratory rate | breaths per minute |
> | `vo2Max` | VO2 max | milliliters per minute per kilogram (ml/kg/min) |

**Platform permissions model**: Permissions work differently on each platform:

* **Android**: Returns a list of granted and declined data types when requesting permissions
* **iOS**: Does not return any information about permission status. The OS will prompt the user when data is first requested, and you won't get confirmation about which permissions were granted

**Important considerations**

* All health data values are returned in metric units only
* Our team can add support for additional data types if required
* Some data types (like sleep) may only be available for recent timeframes
* Date range limitations vary by platform and data type

## Integration guide

Follow the steps below to configure the plugin and use the JavaScript Bridge functions.

### App configuration

#### Enable the plugin

1. **Navigate to Plugins**: In Median App Studio, go to **Native Plugins** and select **Health Bridge**
2. **Enable Health Bridge**: Toggle **Plugin Enabled** on
3. **Configure the iOS permission description**: Explain to users why your app needs access to their Health data (see below)
4. **Select Android read permissions**: Enable only the health data types your app uses (see below)
5. **Save and rebuild**: Click **Save** and rebuild your app for the changes to take effect

![Health Bridge plugin settings in App Studio with iOS permission description and Android read permissions](https://mintcdn.com/median-co/LHRTJUE8ZYxTx6BK/images/docs/health-bridge-config.png?fit=max\&auto=format\&n=LHRTJUE8ZYxTx6BK\&q=85\&s=3fb1d9b8201d98dc5273442ecffbdd1d)

Health Bridge plugin configuration

### JavaScript Bridge functions

Follow these steps to start using the Health Bridge plugin in your app:

#### Step 1: Request permissions

Although not required, we recommend calling `requestPermissions()` upfront as it improves user transparency and experience. This prompts users to grant access to the specific health data types your app will use.

Median JavaScript Bridge

```javascript JavaScript  theme={null}
await median.healthBridge.requestPermissions(["steps", "sleep", "calorieIntake"]);
```

This method accepts an array of data types and returns an object indicating which permissions were granted or declined.

> [!WARNING]
>
> **Platform caveats**
>
> * **Android**: Returns a list of granted and declined data types.
> * **iOS**: Does not return any information about permission status. The OS will prompt the user when data is first requested, and you won't get confirmation about which permissions were granted.

You can optionally skip `requestPermissions()` and directly call `getData()` (next step), and the OS will handle permissions automatically.

#### Step 2: Fetch health data

After permissions are granted (or requested implicitly), use the `getData()` method to retrieve health data. You can define the following parameters:

* The specific `dataTypes` to fetch (from the supported list)
* A `startDate` and `endDate` in ISO 8601 format
* An optional `bucket` to group data (for example, by day or hour)

**Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `dataTypes` | `Array<string>` | Yes | The specific data types to fetch (from the supported list) |
| `startDate` | `string` | Yes | Start date in ISO 8601 format |
| `endDate` | `string` | Yes | End date in ISO 8601 format |
| `bucket` | `string` | No | Optional grouping for data (default: 'raw') |

**Bucket options:**

| Bucket | Description |
| - | - |
| `raw` | Raw, ungrouped data points |
| `minute` | Data grouped per minute |
| `hour` | Data grouped per hour |
| `day` | Data grouped per day (recommended) |

Median JavaScript Bridge

```javascript JavaScript theme={null}
const result = await median.healthBridge.getData({
  dataTypes: granted, // list of granted permissions from previous step
  startDate: "2025-05-01T00:00:00Z",
  endDate: "2025-05-08T00:00:00Z",
  bucket: "day",
});

console.log(result.data.steps);
// [
// { timestamp: '2025-05-01T00:00:00Z', value: 8123 },
// { timestamp: '2025-05-02T00:00:00Z', value: 7890 },
// ...
// ]
```

Want to show a daily step chart for the past week? Fetch steps with `bucket: 'day'` and map the values to your chart component.

**Tip:** Make sure your date range doesn't exceed platform limitations. Some data types (like sleep) may only be available for recent timeframes.

**Example response**

```json JSON theme={null}
{
"data": {
  "height": [
    {
      "start": "2025-12-03T15:30:00.000Z",
      "end": "2025-12-03T15:30:00.000Z",
      "value": 1.87
    }
  ],
  "weight": [],
  "steps": [
    {
      "start": "2025-12-03T15:30:00.000Z",
      "end": "2025-12-03T15:30:00.000Z",
      "value": 5000
    },
    {
      "end": "2025-12-02T15:30:00.000Z",
      "start": "2025-12-02T15:30:00.000Z",
      "value": 4500
    }
  ]
}
}
```

## Integration testing

> [!WARNING]
>
> **Testing requirements**
>
> Due to callouts to Apple services, the Health Bridge integration cannot be tested in the App Studio virtual simulator. Instead, any integration tests must be run on a physical device or on Xcode or Android Studio simulators.

### Testing on iOS

#### Step 1: Install your app

Based on your test setup, you can install the app on a physical device via TestFlight or [iOS binary](https://docs.median.co/docs/build-ios-binary). If you install the app using TestFlight or an iOS binary, the app comes fully built including the necessary capabilities.

**Build locally with Xcode**

If you want to build and test the app locally on macOS, follow the steps below to build your iOS app [from source](https://docs.median.co/docs/build-ios-from-source.md) and add the HealthKit capability.

You can reference the following to confirm that the capability has been added as expected:

![Signing & Capabilities tab in Xcode showing the HealthKit capability](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/73c5c728ebe99e1224513a250e78caf84b4a9d27959decd6939747efebbd1024-Screenshot_2025-12-03_at_11.15.55.png?fit=max\&auto=format\&n=7LCOHMhgIef7ewYE\&q=85\&s=3d61ebeca7b21b73da524de1961632a0)

Xcode app with HealthKit capability

#### Step 2: Add test data

Follow the steps below to add test data to your iOS simulator using the Health app:

| Step 1 | Step 2 | Step 3 |
| :-: | :-: | :-: |
| ![Health app icon on the iOS simulator home screen](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/93434d9c7a1b1d9526f86c8d95aa78a73e99199ad3ce0a5982318320ff5d04bc-Screenshot_2025-12-03_at_11.29.10.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=ad6f4eb6ccc64c7660a920a09e2d3706) | ![Adding a data point with the plus button in the Health app](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/e79b4e2034116675065c1043c39ea950a6d193bde01e6c3d98a640743ae72f11-Screenshot_2025-12-03_at_11.30.00.png?fit=max\&auto=format\&n=yvThAkXSLqPa6nzP\&q=85\&s=59007faa4107b390419c799bef2afdd8) | ![Test data listed in the Health app](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/d71b4ed75a8a0ad81907860f5b1abb659fcb05a0b92522276b62f83275d6a456-Screenshot_2025-12-03_at_11.30.29.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=fa7a741d4dc3fdb9a0ee5758549ea7b6) |
| Suspend the app and find the 'Health' app on your home screen. | Select a metric and manually add test data using the '+' button | Confirm that your test data has been added in the Health app |

#### Step 3: Access your data

After adding test data to your account, follow the steps below to access the data through Health Bridge:

| Step 1 | Step 2 | Step 3 |
| :-: | :-: | :-: |
| ![Selecting data types, bucket, and date range on the demo page](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/c1842880c7736a706ed6030739241666633f889565a6c4442acdcff611c17024-Screenshot_2025-12-03_at_12.09.21.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=114b0d060f7cc228350858d2d9f420d2) | ![iOS Health access permission prompt](https://mintcdn.com/median-co/dZQPJ_0wlG7WNBTy/images/docs/4a264ae575a92db90fe02ec73c722c5e0de6e9606593f4da1369d37e9a03f4f4-Screenshot_2025-12-03_at_12.09.31.png?fit=max\&auto=format\&n=dZQPJ_0wlG7WNBTy\&q=85\&s=25f4f6c5055f68b2dd387a6256b56ab6) | ![Returned health data shown as a JSON object](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/cb88d3018a175bbc9bcb847d1c1464481caa25ca17c2e892dc4dd4c858ed0236-Screenshot_2025-12-03_at_12.09.45.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=3103843b2a3004dbc22e71ee1711e1e5) |
| Select the data points, bucket and date range for the request | Confirm the access | Access the returned data in the JSON object |


## Related topics

- [Tutorial: Build a fitness tracker app with Lovable and Median](https://docs.median.co/docs/getting-started-with-lovable.md)
- [Native functionality](https://docs.median.co/docs/native-functionality.md)
- [Changelog](https://docs.median.co/docs/changelog.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.