Health Bridge
The Health Bridge plugin allows your Median app to access and sync health data from users' devices using Apple HealthKit (iOS) and Google Health Connect (Android). This plugin provides a unified interface to fetch health metrics such as steps, heart rate, calories, and sleep data - enabling you to build powerful wellness and fitness features in your app.
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.
Supported Platforms
- iOS - Apple HealthKit
- Android - Google Health Connect
Typical Use Cases
- Displaying a user's daily or weekly step count
- Creating activity rings or health streaks
- Personalized fitness insights
- Sleep or recovery tracking
Developer Demo
Display our demo page in your app to test during development https://median.dev/health-bridge/
Implementation Guide
Follow these steps to start using the Health Bridge plugin in your app:
1. Request Permissions (Optional but Recommended)
Although not required, calling requestPermissions()
upfront improves user transparency and experience. This prompts users to grant access to the specific health data types your app will use.
const { granted, declined } = await HealthBridge.requestPermissions([
'steps',
'sleep',
'calorieIntake',
]);
This method accepts an array of data types and returns an object indicating which permissions were granted or declined.
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.
Supported Data Types:
The following health data types are supported by Health Bridge. All values are returned in metric units only.
Data Type | Description | Unit |
---|---|---|
steps | Number of steps taken | count |
distance | Distance walked or run | meters (m) |
activeEnergy | Active calories burned | kilocalories (kcal) |
exerciseTime | Time spent exercising | minutes (min) |
height | User's height | centimeters (cm) |
weight | User's weight | kilograms (kg) |
bmi | Body Mass Index | unitless |
calorieIntake | Dietary calorie intake | kilocalories (kcal) |
waterIntake | Water consumed | milliliters (ml) |
sleep | Sleep duration | minutes (min) |
Note:
Imperial units are not currently supported. You may need to convert values manually if your UI requires them.
You can skip requestPermissions() and directly call getData() (next step) — the OS will handle permissions automatically.
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
andendDate
in ISO 8601 format - An optional
bucket
to group data (e.g., by day or hour)
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 },
// ...
// ]
Available Data Buckets
Bucket | Description |
---|---|
raw | Raw, ungrouped data points |
minute | Data grouped per minute |
hour | Data grouped per hour |
day | Data grouped per day (recommended) |
Want to show a daily step chart for the past week? Just 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.
Updated 19 days ago