React Native Health Connect: read and write steps, heart rate, sleep, workouts and 42 Health Connect record types from React Native — TypeScript-first TurboModule with an Expo config plugin.
android-health-connect is a React Native Health Connect library (TurboModule, TypeScript, Expo-compatible) for integrating with Android Health Connect — the unified health & fitness data platform on Android 10+ (API 29+).
iOS? This library is Android-only. For Apple HealthKit on iOS, use
@kingstinct/react-native-healthkitalongside it.
Docs site: solutionforest.github.io/AndroidHealthConnect (guides · record types) · AI agent skill: skills.md (install it)
Quality (since 0.3.6): max-strict TypeScript · type-aware ESLint · Jest coverage gates · Kotlin allWarningsAsErrors · CI fails on drop. Security model: SECURITY.md.
| Area | Status | Notes |
|---|---|---|
| Android | ✅ Supported | API 29+ / Android 10+ |
| iOS | ❌ Not supported | No native iOS implementation |
| React Native New Architecture | ✅ Required | TurboModules / RN 0.84+ |
| Expo | ✅ Supported | SDK 50+ via config plugin |
| Bare React Native | ✅ Supported | Manual manifest + rationale setup |
| Health Connect permissions | ✅ Supported | Request / check / revoke |
| Read / write / delete records | ✅ Supported | See Supported record types |
| Aggregate / bucket queries | ✅ Supported | aggregateRecord, aggregateGroupByDuration, aggregateGroupByPeriod |
| Exercise routes | ✅ Supported | Write on ExerciseSession; read DATA / NO_DATA / CONSENT_REQUIRED + requestExerciseRoute |
| Changelog sync | ✅ Supported | getChangesToken / getChanges (upsert + delete pages; ~30-day tokens) |
| Planned exercise | ✅ Supported | PlannedExerciseSession when plannedExercise feature is available |
| Library upgrade reminder | ✅ Supported | checkLibraryUpdate() + weekly CI (HC SDK / release drift → issue) |
| CI / quality gates | ✅ GitHub-hosted | lint, typecheck, Jest + Kotlin unit tests, library + Android build, audit |
| Distribution | ✅ npmjs.org + GitHub Releases | Primary: npmjs. Mirror: GitHub Packages. Release .tgz has SBOM + attestations |
| CodeQL | ✅ Supported | On main PRs/pushes + weekly schedule |
This library is a TurboModule — it needs React Native 0.84+ (New Architecture).
CI builds and tests against RN 0.88; 0.84–0.87 remain supported (no 0.88-only APIs are used).
RN 0.6x / 0.7x / <0.84 are not supported on either release line.
Pick a line by Android toolchain (HC SDK / AGP), not by RN major:
| Package | RN | Node | connect-client |
Min AGP | compileSdk | Branch / tag |
|---|---|---|---|---|---|---|
0.3.18 (default) |
≥0.84 | ≥22.22 | 1.2.0-alpha06 |
9.1.0 | 37 | main |
0.2.4 (maintenance) |
≥0.84 | ≥22.11 | 1.1.0 (stable) |
8.9.1 | 36 | release/0.2.x |
# npmjs.org (default — no .npmrc needed)
yarn add @solutionforest/android-health-connect@0.3.18 # AGP 9.1+ / compileSdk 37
yarn add @solutionforest/android-health-connect@0.2.4 # AGP 8.9.1+ / compileSdk 36 (dist-tag release-0.2)| Requirement | Value for 0.3.18 |
|---|---|
| Install | @solutionforest/android-health-connect from npmjs.org |
| Health Connect Jetpack SDK | connect-client:1.2.0-alpha06 |
| Android Gradle Plugin | 9.1.1 (min 9.1.0) |
| Gradle | 9.3.1+ (required by AGP 9.1; RN 0.88 apps need 9.4.1+ for AGP 9.2) |
| compileSdk | 37 |
| Android OS | 10 (API 29)+ |
| Health Connect app | Required on Android 9–13; built-in on Android 14+ |
| React Native | ≥0.84 (New Architecture / TurboModules), tested on 0.88 — not 0.6x / 0.7x |
| Node.js | ≥22.22 |
| Expo (optional) | SDK 50+ |
Official notes (full changelog):
| SDK version | Date | What changed |
|---|---|---|
| 1.2.0-alpha06 | 2026-08-26 | Updated Health Connect release and dev signing certificates |
| 1.2.0-alpha05 | 2026-08-12 | Jetpack SDK minSdk → API 24; secured intents on Android < 14; signature validation fix |
| 1.2.0-alpha04 | 2026-04-22 | Matchmaking APIs |
| 1.2.0-alpha03 | 2026-03-25 | Richer exercise fields; change-log pageSize; activity intensity |
| 1.2.0-alpha02 | 2025-10-08 | Additional device type enums |
| 1.2.0-alpha01 | 2025-07-30 | Skin temperature / mindfulness compat; activity intensity (Android 14+) |
| 1.1.0 (stable) | 2025-10-08 | First stable connect-client |
JS API: 42 record types, feature checks, Matchmaking, PHR. Feature-gated types need getFeatureStatus(Feature.*) === FeatureStatus.AVAILABLE.
Same scoped name on both registries: @solutionforest/android-health-connect. Full dual-registry guide: docs site → Install.
| Registry | Role | How |
|---|---|---|
| npmjs.org | Primary | yarn add / npm i — no .npmrc |
| GitHub Packages | Mirror + Release .tgz (SBOM / attestations) |
Scope @solutionforest → npm.pkg.github.com + PAT (read:packages) |
# Default (0.3.x): connect-client 1.2.0-alpha06 — needs AGP 9.1+ / compileSdk 37
yarn add @solutionforest/android-health-connect@0.3.18
# or
npm install @solutionforest/android-health-connect@0.3.18
# Maintenance (0.2.x): connect-client 1.1.0 stable — AGP 8.9.1+ / compileSdk 36
yarn add @solutionforest/android-health-connect@release-0.2# .npmrc
@solutionforest:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PATyarn add @solutionforest/android-health-connect@0.3.18Use a classic PAT with read:packages (SSO-authorize for solutionforest if required).
Alternatives: install from git (solutionforest/AndroidHealthConnect#v0.3.18) or download the Release .tgz.
Pushing a v* tag runs the Release workflow: packs .tgz, uploads to the GitHub Release, publishes to npmjs.org via Trusted Publishing (OIDC), and mirrors to GitHub Packages.
The package ships skills.md: an agent skill that tells AI coding agents (Cursor, Claude Code, Codex, …) how to use this library correctly. It covers which version line to pick, the hard constraints (Android only, RN 0.84+ New Architecture), the availability → permissions → read order, and resume polling. Install it into your app repo so your agent follows it.
Copy it from the installed package, so the skill always matches the version you installed:
# Cursor
mkdir -p .cursor/skills/android-health-connect
cp node_modules/@solutionforest/android-health-connect/skills.md \
.cursor/skills/android-health-connect/SKILL.md
# Claude Code
mkdir -p .claude/skills/android-health-connect
cp node_modules/@solutionforest/android-health-connect/skills.md \
.claude/skills/android-health-connect/SKILL.md
# Other agents (Codex, Gemini CLI, … — any tool that reads .agents/skills)
mkdir -p .agents/skills/android-health-connect
cp node_modules/@solutionforest/android-health-connect/skills.md \
.agents/skills/android-health-connect/SKILL.mdOr download the latest from the docs site, before the package is installed:
curl -fsSL --create-dirs \
-o .cursor/skills/android-health-connect/SKILL.md \
https://solutionforest.github.io/AndroidHealthConnect/skills.mdOr paste this prompt into your agent:
Install the android-health-connect agent skill: download https://solutionforest.github.io/AndroidHealthConnect/skills.md and save it as
SKILL.mdin this project's skills folder (.cursor/skills/android-health-connect/for Cursor,.claude/skills/android-health-connect/for Claude Code, otherwise.agents/skills/android-health-connect/). Then follow it whenever you work with@solutionforest/android-health-connect.
Commit the skill folder so the whole team's agents get it. Re-copy after upgrading the package.
If you are using Expo (SDK 50+), add the library's config plugin to your app.json or app.config.js. The plugin automatically handles adding the required Health Connect intent filters to your Android manifest.
{
"expo": {
"plugins": [
[
"@solutionforest/android-health-connect",
{
"permissions": [
"android.permission.health.READ_STEPS",
"android.permission.health.WRITE_STEPS",
"android.permission.health.READ_HEART_RATE"
]
}
]
]
}
}If you omit permissions (or pass []), the plugin still adds the required
intent-filters but does not declare any health permissions — list only what
your app needs:
{
"expo": {
"plugins": ["@solutionforest/android-health-connect"]
}
}After updating app.json, run npx expo prebuild to regenerate the native Android project.
Health Connect is a native module, so it doesn't run in Expo Go. Use a development build:
npx expo install expo-dev-client
npx expo prebuild --platform android
npx expo run:androidThe library needs minSdkVersion 29. If your app targets lower, raise it with
expo-build-properties.
For a working setup, see the Expo example app (Expo SDK 58, dev client, config plugin). It checks availability, requests permission, reads the last 7 days of steps and aggregates them.
Health Connect requires every permission your app uses to be declared in the host app's manifest (the library manifest is merged automatically, but you must also add them to your app):
<manifest ...>
<!-- Declare only the permissions your app actually needs -->
<uses-permission android:name="android.permission.health.READ_STEPS" />
<uses-permission android:name="android.permission.health.WRITE_STEPS" />
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
<!-- ... other permissions ... -->
<application ...>
<activity android:name=".MainActivity" ...>
<!-- Required for Health Connect permission rationale (Android ≤ 13) -->
<intent-filter>
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>
<!-- Required for Health Connect permission UI (Android 14+) -->
<intent-filter>
<action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
<category android:name="android.intent.category.HEALTH_PERMISSIONS" />
</intent-filter>
</activity>
</application>
</manifest>Create res/values/health_permissions.xml:
<resources>
<string name="health_permissions_rationale">
This app uses Health Connect to read and write your health data.
</string>
</resources>Runnable host demo (buttons for the flows below): example/ —
see example/README.md for a first-run checklist.
import {
ensureAvailable,
isHealthConnectAvailable,
getHealthConnectAvailability,
openHealthConnectApp,
Availability,
} from '@solutionforest/android-health-connect';
// Quick gate — opens Play Store / Settings when notInstalled (default):
const status = await ensureAvailable();
if (status !== Availability.AVAILABLE) {
// notInstalled (store opened) | notSupported (hide HC UI)
}
// Or check without side effects:
const availability = await isHealthConnectAvailable();
// 'available' | 'notInstalled' | 'notSupported'
if (availability === Availability.NOT_INSTALLED) {
openHealthConnectApp(); // Play Store market:// (or Settings on Android 14+)
}
// Prefer details when diagnosing install vs built-in vs China / HMS:
const info = await getHealthConnectAvailability();
// info.provider: 'framework' (Android 14+) | 'apk' (9–13) | 'none'
// info.sdkStatus: 1 = UNAVAILABLE, 2 = PROVIDER_UPDATE_REQUIRED, 3 = AVAILABLE
// info.googlePlayServicesAvailable / playStoreAvailable / advice| Situation | What happens | What to do |
|---|---|---|
| Android 14+ | Health Connect is built into the system | Use Settings / openHealthConnectSettings() |
| Android 9–13 | Health Connect is a Play Store APK | openHealthConnectApp() → Play Store install/update |
sdkStatus === 3 |
Available (not “version too old”) | Safe to call APIs |
| Mainland China / no GMS | HC requires Google Play services; CN Play Storefront does not list HC | status: 'notSupported'; hide HC UI — cannot install via Play |
| Huawei / HMS without GMS | Same as no GMS | Unsupported for Health Connect |
| Samsung / Xiaomi data gaps | Vendor apps must write into HC; library only reads HC | Enable Health Connect sharing in the vendor app |
Official availability: Check Health Connect availability.
import {
requestPermissions,
Permission,
} from '@solutionforest/android-health-connect';
const needed = [
Permission.READ_STEPS,
Permission.WRITE_STEPS,
Permission.READ_HEART_RATE,
];
const granted = await requestPermissions(needed);
console.log('Granted:', granted);
// Quick checks (no dialog):
import {
hasPermissions,
missingPermissions,
ensurePermissions,
} from '@solutionforest/android-health-connect';
if (!(await hasPermissions(needed))) {
const missing = await missingPermissions(needed);
console.log('Still missing:', missing);
}
// Or request any missing in one shot:
const ensured = await ensurePermissions(needed);
if (!ensured.allGranted) {
console.log('User denied:', ensured.missing);
}History / background (optional special permissions): by default HC only lets apps read ~30 days before first grant, and only while foregrounded. Declare in the host manifest, gate on feature status, then request:
import {
getFeatureStatus,
requestPermissions,
Permission,
Feature,
FeatureStatus,
} from '@solutionforest/android-health-connect';
import type { HealthPermission } from '@solutionforest/android-health-connect';
const extra: HealthPermission[] = [];
if ((await getFeatureStatus(Feature.READ_HEALTH_DATA_HISTORY)) === FeatureStatus.AVAILABLE) {
extra.push(Permission.READ_HEALTH_DATA_HISTORY);
}
if ((await getFeatureStatus(Feature.READ_HEALTH_DATA_IN_BACKGROUND)) === FeatureStatus.AVAILABLE) {
extra.push(Permission.READ_HEALTH_DATA_IN_BACKGROUND);
}
await requestPermissions([Permission.READ_STEPS, ...extra]);<uses-permission android:name="android.permission.health.READ_HEALTH_DATA_HISTORY" />
<uses-permission android:name="android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND" />import {
readSteps,
timeRangeLastDays,
} from '@solutionforest/android-health-connect';
const { records, pageToken } = await readSteps({
timeRangeFilter: timeRangeLastDays(7),
ascendingOrder: true,
pageSize: 100,
});
records.forEach(r => console.log(r.count, r.startTime));Using the generic helper:
import {
readRecords,
RecordType,
timeRangeLastDays,
} from '@solutionforest/android-health-connect';
import type { WeightRecord } from '@solutionforest/android-health-connect';
const { records } = await readRecords<WeightRecord>(RecordType.WEIGHT, {
timeRangeFilter: timeRangeLastDays(30),
});Prefer RecordType.* over hand-typed 'Steps' strings (same idea as Permission.*).
Times use a Carbon-style fluent Instant — now().subHours(1) reads like English:
import {
writeRecords,
RecordType,
now,
timeRangeLastHours,
} from '@solutionforest/android-health-connect';
const { startTime, endTime } = timeRangeLastHours(1);
// or: now().subHours(1).until(now())
const { recordIdsList } = await writeRecords([
{
recordType: RecordType.STEPS,
count: 8000,
startTime,
endTime,
},
{
recordType: RecordType.WEIGHT,
weight: 75.5, // kg
time: now().subMinutes(30).toISOString(),
},
]);updateRecords edits existing rows. Pass the same shape as write, plus
metadata.id from a prior read (required). Optional recordingMethod / device
round-trip when present on the read record.
import {
readSteps,
updateRecords,
RecordingMethod,
} from '@solutionforest/android-health-connect';
const { records } = await readSteps({
timeRangeFilter: { startTime: '...', endTime: '...' },
});
const existing = records[0];
if (!existing?.metadata?.id) throw new Error('nothing to update');
await updateRecords([
{
...existing,
count: existing.count + 100,
metadata: {
...existing.metadata,
id: existing.metadata.id,
recordingMethod: existing.metadata.recordingMethod ?? RecordingMethod.MANUAL_ENTRY,
},
},
]);Requires WRITE_EXERCISE_ROUTE to insert a route with a session, and
READ_EXERCISE_ROUTES to read routes written by other apps. Omit optional
altitude / accuracy fields instead of sending empty objects.
import {
writeRecords,
readExerciseSessions,
requestExerciseRoute,
getFeatureStatus,
ExerciseType,
RecordType,
Feature,
FeatureStatus,
now,
timeRangeLastDays,
} from '@solutionforest/android-health-connect';
const end = now();
const start = end.subHours(1);
const mid = end.subMinutes(30);
await writeRecords([
{
recordType: RecordType.EXERCISE_SESSION,
exerciseType: ExerciseType.RUNNING,
startTime: start.toISOString(),
endTime: end.toISOString(),
exerciseRoute: {
route: [
{ time: start.toISOString(), latitude: 51.5, longitude: -0.12, altitude: 19 },
{ time: mid.toISOString(), latitude: 51.51, longitude: -0.11 },
],
},
},
]);
// Optional 1.2 fields — gate on FEATURE_EXERCISE_SESSION_IMPROVEMENTS:
if ((await getFeatureStatus(Feature.EXERCISE_SESSION_IMPROVEMENTS)) === FeatureStatus.AVAILABLE) {
await writeRecords([
{
recordType: RecordType.EXERCISE_SESSION,
exerciseType: ExerciseType.RUNNING,
startTime: start.toISOString(),
endTime: end.toISOString(),
rateOfPerceivedExertion: 6.5,
// plannedExerciseSessionId: '<id from PlannedExerciseSession write>',
},
]);
}
const { records } = await readExerciseSessions({
timeRangeFilter: timeRangeLastDays(7),
});
for (const session of records) {
const route = session.exerciseRoute;
if (!route || route.type === 'NO_DATA') continue;
if (route.type === 'CONSENT_REQUIRED') {
const granted = await requestExerciseRoute(session.metadata?.id ?? '');
console.log(granted?.route);
} else {
console.log(route.route); // LengthResult altitude / accuracy when present
}
}Requires getFeatureStatus(Feature.PLANNED_EXERCISE) === FeatureStatus.AVAILABLE and
READ_PLANNED_EXERCISE / WRITE_PLANNED_EXERCISE.
import {
requestPermissions,
writeRecords,
readPlannedExerciseSessions,
ExerciseType,
ExerciseSegmentType,
ExercisePhase,
Permission,
RecordType,
now,
} from '@solutionforest/android-health-connect';
await requestPermissions([
Permission.READ_PLANNED_EXERCISE,
Permission.WRITE_PLANNED_EXERCISE,
]);
const start = now().addDays(2);
const end = start.addMinutes(90);
await writeRecords([
{
recordType: RecordType.PLANNED_EXERCISE_SESSION,
exerciseType: ExerciseType.RUNNING,
startTime: start.toISOString(),
endTime: end.toISOString(),
title: 'Lake run',
blocks: [
{
repetitions: 1,
description: 'Three laps',
steps: [
{
exerciseType: ExerciseSegmentType.RUNNING,
exercisePhase: ExercisePhase.ACTIVE,
completionGoal: { type: 'Repetitions', repetitions: 3 },
performanceTargets: [
{ type: 'HeartRate', minHeartRate: 90, maxHeartRate: 110 },
],
},
],
},
],
},
]);
await readPlannedExerciseSessions({
timeRangeFilter: now().until(now().addDays(14)),
});Health Connect has no push observer. On a real phone, after you resume /
re-open the app, the first read or aggregate is often 0 / empty — vendor apps
(Samsung Health, Fitbit, …) may still be writing into HC. Google’s guidance: sync
when the app becomes foreground, and optionally poll while it stays open.
useForegroundPoll does this for you: it polls on mount and on every resume,
aborts the in-flight poll when the app backgrounds (so a stale result never
overwrites a newer one), and keeps the last value on timeout.
import {
aggregateRecord,
timeRangeToday,
useForegroundPoll,
RecordType,
} from '@solutionforest/android-health-connect';
const stepsOf = (r: { metrics: Record<string, unknown> }) => {
const n = r.metrics['COUNT_TOTAL'];
return typeof n === 'number' ? n : 0;
};
function TodaySteps({ granted }: { granted: boolean }) {
const { value, satisfied, loading, error, refresh } = useForegroundPoll(
() =>
aggregateRecord({ recordType: RecordType.STEPS, timeRangeFilter: timeRangeToday() }),
{
// "> 0" only when you expect activity; a real 0-step day times out.
ready: (r) => stepsOf(r) > 0,
timeoutMs: 20_000,
intervalMs: 1_000,
enabled: granted, // wait until permissions are granted
}
);
if (error) return <Text onPress={refresh}>Couldn’t read steps. Tap to retry</Text>;
return (
<Text onPress={refresh}>
{value ? stepsOf(value) : '–'} steps
{loading ? ' · syncing…' : !satisfied && value ? ' · no new data yet' : ''}
</Text>
);
}Outside React, use pollOnForeground(fetch, { ready, onResult, onError });
it returns { refresh, stop }. For a single one-off wait, use
pollUntil (soft) or waitUntil (throws WaitTimeoutError).
import {
timeRangeLastDays,
waitForRecords,
readAllRecords,
RecordType,
} from '@solutionforest/android-health-connect';
// After your own writeRecords — wait until the row is readable:
await waitForRecords({
recordType: RecordType.STEPS,
timeRangeFilter: timeRangeLastDays(1),
minCount: 1,
timeoutMs: 15_000,
});
const all = await readAllRecords(RecordType.STEPS, {
timeRangeFilter: timeRangeLastDays(7),
});aggregateRecord uses Instant time ranges. Prefer
aggregateGroupByDuration for fixed buckets (also Instant — avoids Android 14+
UTC wall-clock shift). Use aggregateGroupByPeriod for calendar days/weeks
(LocalDateTime in the device zone).
import {
aggregateRecord,
aggregateGroupByDuration,
timeRangeLastDays,
RecordType,
now,
} from '@solutionforest/android-health-connect';
const total = await aggregateRecord({
recordType: RecordType.STEPS,
timeRangeFilter: timeRangeLastDays(7),
});
console.log(total.metrics['COUNT_TOTAL']); // number | null
const hourly = await aggregateGroupByDuration({
recordType: RecordType.STEPS,
timeRangeFilter: now().subDays(1).until(now()),
timeRangeSlicer: { unit: 'hours', value: 1 },
});
hourly.forEach((row) => {
console.log(row.startTime, row.result.metrics['COUNT_TOTAL']);
});import { deleteRecordsByTime, deleteRecordsById, RecordType, now } from '@solutionforest/android-health-connect';
// By time range
await deleteRecordsByTime(RecordType.STEPS, now().subDays(1), now());
// By ID
await deleteRecordsById(RecordType.STEPS, ['record-id-1', 'record-id-2']);Tokens expire after ~30 days. Prefer one record type per token. Loop while
hasMore; if changesTokenExpired, backfill with readRecords then mint a new
token. Optional pageSize (1–5000) is a soft hint.
import {
getChangesToken,
pullChanges,
RecordType,
} from '@solutionforest/android-health-connect';
let token = await getChangesToken({ recordTypes: [RecordType.STEPS] });
const batch = await pullChanges(token, { pageSize: 500 });
if (batch.changesTokenExpired) {
// backfill with readRecords, then mint a fresh token
token = await getChangesToken({ recordTypes: [RecordType.STEPS] });
} else {
for (const { record } of batch.upsertionChanges) {
console.log('upsert', record.recordType, record.metadata?.id);
}
for (const { recordId } of batch.deletionChanges) {
console.log('delete', recordId);
}
token = batch.nextChangesToken; // persist for next sync
}Typed hooks wrap the imperative API. Each one fetches on mount, fetches again
whenever the app returns to the foreground (built on pollOnForeground),
refetches when its arguments change (compared by value, so inline arrays and
objects are fine), and drops results that arrive after unmount or for older
arguments.
import {
Permission,
RecordType,
timeRangeLastDays,
timeRangeToday,
useAggregate,
useHealthConnectAvailability,
useHealthConnectPermissions,
useMostRecentRecord,
useReadRecords,
type StepsRecord,
type WeightRecord,
} from '@solutionforest/android-health-connect';
function Dashboard() {
const availability = useHealthConnectAvailability();
const [perms, request] = useHealthConnectPermissions([
Permission.READ_STEPS,
Permission.READ_WEIGHT,
]);
const ready =
availability.value === 'available' && perms.value?.allGranted === true;
// Pass a function for "now"-relative ranges: it is re-evaluated on every
// fetch and does not restart the query on re-render.
const today = useAggregate(RecordType.STEPS, () => timeRangeToday(), {
enabled: ready,
});
const week = useReadRecords<StepsRecord>(RecordType.STEPS, {
timeRangeFilter: () => timeRangeLastDays(7),
enabled: ready,
});
const weight = useMostRecentRecord<WeightRecord>(RecordType.WEIGHT, {
enabled: ready,
});
if (availability.value !== 'available') return <Text>Install Health Connect</Text>;
if (!perms.value?.allGranted) return <Button title="Allow access" onPress={() => void request()} />;
return (
<Text>
{String(today.value?.metrics['COUNT_TOTAL'] ?? '–')} steps today ·{' '}
{week.value?.records.length ?? 0} step records this week ·{' '}
{weight.value ? `${weight.value.weight} kg` : 'no weight'}
</Text>
);
}| Hook | value |
Notes |
|---|---|---|
useHealthConnectAvailability(opts?) |
'available' | 'notInstalled' | 'notSupported' |
Updates after the user installs HC and comes back |
useHealthConnectPermissions(perms, opts?) |
[status, request]; status.value is { granted, missing, allGranted } |
request() shows the dialog for missing permissions only and resolves with the re-checked result |
useReadRecords<T>(type, opts?) |
ReadRecordsResponse<T> |
Same options as readRecords; timeRangeFilter may be a function |
useMostRecentRecord<T>(type, opts?) |
T | null |
Newest record in the window (default: last 30 days) |
useAggregate(type, range, opts?) |
AggregateResult |
range may be a function, e.g. () => timeRangeToday() |
useChanges(token, opts?) |
PullChangesResult |
Changelog sync; see below |
The data hooks return { value, satisfied, loading, error, refresh }, the same
shape as useForegroundPoll, and accept enabled, ready, timeoutMs and
intervalMs. Without ready each fetch is a single read. Add ready to keep
polling through the "0 right after resume" gap:
const steps = useAggregate(RecordType.STEPS, () => timeRangeToday(), {
ready: (r) => ((r.metrics['COUNT_TOTAL'] as number | null) ?? 0) > 0,
timeoutMs: 20_000,
});
// steps.satisfied === false → timed out; the value may be a real 0.useChanges(token, { onChanges }) drains the changelog with pullChanges on
mount and on every resume. After each pull it continues from
nextChangesToken, so persist that token in onChanges. Pass null to pause
until you have a token. When value.changesTokenExpired is true, backfill and
pass a fresh token from getChangesToken; a new token prop restarts from it.
const [token, setToken] = useState<string | null>(storedToken);
useChanges(token, {
onChanges: ({ upsertionChanges, deletionChanges, nextChangesToken, changesTokenExpired }) => {
if (changesTokenExpired) {
void backfill().then(() =>
getChangesToken({ recordTypes: [RecordType.STEPS] }).then(setToken)
);
return;
}
applyToLocalDb(upsertionChanges, deletionChanges);
saveToken(nextChangesToken);
},
});The 19 parity-batch types marked below are unit-tested but
⚠️ not fully tested on a real device yet.
| Record type | Read | Write | Notes |
|---|---|---|---|
Steps |
✅ | ✅ | |
HeartRate |
✅ | ✅ | |
SleepSession |
✅ | ✅ | |
ActiveCaloriesBurned |
✅ | ✅ | |
TotalCaloriesBurned |
✅ | ✅ | |
Distance |
✅ | ✅ | |
Weight |
✅ | ✅ | |
Height |
✅ | ✅ | |
BloodPressure |
✅ | ✅ | |
BloodGlucose |
✅ | ✅ | |
OxygenSaturation |
✅ | ✅ | |
BodyTemperature |
✅ | ✅ | |
BodyFat |
✅ | ✅ | |
Hydration |
✅ | ✅ | |
ExerciseSession |
✅ | ✅ | Optional exerciseRoute; read returns DATA / NO_DATA / CONSENT_REQUIRED; optional RPE / plannedExerciseSessionId when exerciseSessionImprovements |
PlannedExerciseSession |
✅ | ✅ | Requires getFeatureStatus(Feature.PLANNED_EXERCISE); blocks / steps / goals / targets |
RestingHeartRate |
✅ | ✅ | |
RespiratoryRate |
✅ | ✅ | |
FloorsClimbed |
✅ | ✅ | |
ElevationGained |
✅ | ✅ | |
MindfulnessSession |
✅ | ✅ | Requires getFeatureStatus(Feature.MINDFULNESS_SESSION) |
SkinTemperature |
✅ | ✅ | Requires getFeatureStatus(Feature.SKIN_TEMPERATURE) |
ActivityIntensity |
✅ | ✅ | Requires getFeatureStatus(Feature.ACTIVITY_INTENSITY) |
Nutrition |
✅ | ✅ | |
Vo2Max |
✅ | ✅ | |
Speed |
✅ | ✅ | |
Power |
✅ | ✅ | |
StepsCadence |
✅ | ✅ | |
CyclingPedalingCadence |
✅ | ✅ | |
WheelchairPushes |
✅ | ✅ | |
MenstruationFlow |
✅ | ✅ | |
MenstruationPeriod |
✅ | ✅ | |
OvulationTest |
✅ | ✅ | |
CervicalMucus |
✅ | ✅ | |
IntermenstrualBleeding |
✅ | ✅ | |
SexualActivity |
✅ | ✅ | |
BasalBodyTemperature |
✅ | ✅ | |
LeanBodyMass |
✅ | ✅ | |
BoneMass |
✅ | ✅ | |
BodyWaterMass |
✅ | ✅ | |
BasalMetabolicRate |
✅ | ✅ | |
HeartRateVariabilityRmssd |
✅ | ✅ |
import {
getFeatureStatus,
checkIfMatchmakingIsPossible,
launchMatchmaking,
createMedicalDataSource,
upsertMedicalResources,
readMedicalResources,
MedicalResourceType,
RecordType,
Feature,
FeatureStatus,
FhirVersion,
} from '@solutionforest/android-health-connect';
// Feature availability (skin temperature, mindfulness, activity intensity, matchmaking, PHR, …)
const skinTemp = await getFeatureStatus(Feature.SKIN_TEMPERATURE); // FeatureStatus.AVAILABLE | UNAVAILABLE
// Matchmaking (experimental) — discover apps/devices that can write data you can read
if ((await getFeatureStatus(Feature.MATCHMAKING)) === FeatureStatus.AVAILABLE) {
const { isMatchmakingPossible } = await checkIfMatchmakingIsPossible({
recordTypes: [RecordType.STEPS, RecordType.HEART_RATE],
});
if (isMatchmakingPossible) {
await launchMatchmaking({ recordTypes: [RecordType.STEPS, RecordType.HEART_RATE] });
}
}
// Personal Health Record / medical (experimental) — FHIR MedicalDataSource + MedicalResource
if ((await getFeatureStatus(Feature.PERSONAL_HEALTH_RECORD)) === FeatureStatus.AVAILABLE) {
const source = await createMedicalDataSource({
displayName: 'Clinic FHIR',
fhirBaseUri: 'https://example.com/fhir/',
fhirVersion: FhirVersion.R4,
});
await upsertMedicalResources([
{
dataSourceId: source.id,
fhirVersion: source.fhirVersion,
data: JSON.stringify({ resourceType: 'AllergyIntolerance', id: '1', /* … */ }),
},
]);
const page = await readMedicalResources({
medicalResourceType: MedicalResourceType.ALLERGIES_INTOLERANCES,
medicalDataSourceIds: [source.id],
});
}Check GitHub Releases and show a reminder when a newer library version is available:
import { checkLibraryUpdate, LIBRARY_VERSION } from '@solutionforest/android-health-connect';
const update = await checkLibraryUpdate();
if (update.updateAvailable) {
console.warn(update.advice);
// e.g. show in-app banner: update.currentVersion → update.latestVersion
}| Workflow | What it does |
|---|---|
| CI / CodeQL | Lint, tests, build on ubuntu-latest |
| Version check | Mondays 08:00 UTC — compares HC SDK (Maven) + library (GitHub Release); opens/updates an upgrade-reminder issue. Manual: Actions → Version check → Run workflow. Cron options in .github/workflows/version-check.yml. |
Release (v* tag) |
Packs .tgz + SBOM / attestations → GitHub Release → npmjs.org (OIDC Trusted Publishing) → GitHub Packages mirror |
| Function | Returns | Description |
|---|---|---|
isHealthConnectAvailable() |
Promise<HealthConnectAvailability> |
Check if HC is usable |
getHealthConnectAvailability() |
Promise<HealthConnectAvailabilityInfo> |
Detailed status (framework/apk, GMS, Play Store, advice) |
openHealthConnectApp() |
void |
Open HC app or Play Store |
openHealthConnectSettings() |
void |
Open HC settings |
openHealthConnectDataManagement(pkg?) |
void |
Open permission management |
checkLibraryUpdate(options?) |
Promise<LibraryUpdateInfo> |
Upgrade reminder vs GitHub Releases |
LIBRARY_VERSION |
string |
Current package version |
| Function | Returns | Description |
|---|---|---|
requestPermissions(perms) |
Promise<string[]> |
Show permission dialog |
checkPermissions(perms) |
Promise<string[]> |
Check which are granted |
hasPermissions(perms) |
Promise<boolean> |
True when all listed perms are granted |
missingPermissions(perms) |
Promise<string[]> |
Subset that is not granted |
ensurePermissions(perms, opts?) |
Promise<EnsurePermissionsResult> |
Request any missing (default) + re-check |
ensureAvailable(opts?) |
Promise<availability> |
Quick gate; opens store if notInstalled (default) |
revokeAllPermissions() |
Promise<void> |
Revoke all permissions |
Permission.* |
HealthPermission |
Typed permission string constants |
timeRangeToday() / timeRangeLastDays(n) / timeRangeLastHours(n) |
TimeRangeFilter |
Instant windows for reads/aggregates |
pollUntil(fetch, opts) |
Promise<PollUntilResult> |
Soft poll (resume: first value often 0) |
waitUntil(fetch, opts) |
Promise<T> |
Same as pollUntil but throws on timeout |
useForegroundPoll(fetch, opts) |
{ value, satisfied, loading, error, refresh } |
React hook: poll on mount + every resume |
pollOnForeground(fetch, opts) |
{ refresh, stop } |
Non-React version of useForegroundPoll |
waitForRecords(opts) |
Promise<ReadRecordsResponse> |
Poll readRecords until rows appear |
readAllRecords(type, opts?) |
Promise<T[]> |
Follow pageToken until exhausted |
pullChanges(token, opts?) |
Promise<PullChangesResult> |
Drain changelog pages (hasMore loop) |
| Function | Returns | Description |
|---|---|---|
readRecords<T>(type, options) |
Promise<ReadRecordsResponse<T>> |
Generic read |
writeRecords(records) |
Promise<InsertRecordsResponse> |
Insert records |
updateRecords(records) |
Promise<void> |
Update existing records (metadata.id required) |
deleteRecordsByTime(type, start, end) |
Promise<void> |
Delete by time range |
deleteRecordsById(type, ids) |
Promise<void> |
Delete by IDs |
aggregateRecord(request) |
Promise<AggregateResult> |
Sum/avg/min/max over Instant range |
aggregateGroupByDuration(request) |
Promise<AggregationResultGroupedByDuration[]> |
Fixed buckets (Instant; avoids UTC shift) |
aggregateGroupByPeriod(request) |
Promise<AggregationResultGroupedByPeriod[]> |
Calendar buckets (LocalDateTime) |
requestExerciseRoute(recordId) |
Promise<ExerciseRouteRead | null> |
Consent UI when route is CONSENT_REQUIRED |
getChangesToken(request) |
Promise<string> |
Mint changelog token (~30 days; prefer one type) |
getChanges(token, opts?) |
Promise<GetChangesResponse> |
Upserts/deletes since token; optional pageSize (1–5000) |
readSteps(options?) |
Promise<ReadRecordsResponse<StepsRecord>> |
Convenience helper |
readHeartRate(options?) |
… | Convenience helper |
| (and one per record type, including Mindfulness / SkinTemperature / ActivityIntensity) |
| Hook | Returns | Description |
|---|---|---|
useHealthConnectAvailability(opts?) |
HealthQueryState<HealthConnectAvailability> |
Availability, re-checked on resume |
useHealthConnectPermissions(perms, opts?) |
[HealthQueryState<EnsurePermissionsResult>, request] |
Granted/missing status + request function |
useReadRecords<T>(type, opts?) |
HealthQueryState<ReadRecordsResponse<T>> |
One page of records |
useMostRecentRecord<T>(type, opts?) |
HealthQueryState<T | null> |
Newest record in the window |
useAggregate(type, range, opts?) |
HealthQueryState<AggregateResult> |
Aggregate metrics for a range |
useChanges(token, opts?) |
HealthQueryState<PullChangesResult> |
Changelog sync that advances its own token |
HealthQueryState<T> is { value, satisfied, loading, error, refresh }.
| Function | Returns | Description |
|---|---|---|
getFeatureStatus(feature) |
Promise<'available' | 'unavailable'> |
Check HC feature flags |
checkIfMatchmakingIsPossible(opts?) |
Promise<{ isMatchmakingPossible }> |
Whether Matchmaking UI has candidates |
launchMatchmaking(opts?) |
Promise<boolean> |
Launch Matchmaking activity |
createMedicalDataSource(req) |
Promise<MedicalDataSource> |
Create FHIR data source |
getMedicalDataSources(req?) |
Promise<MedicalDataSource[]> |
List medical data sources |
deleteMedicalDataSourceWithData(id) |
Promise<void> |
Delete source + its resources |
upsertMedicalResources(reqs) |
Promise<MedicalResource[]> |
Insert/update FHIR resources |
readMedicalResources(req) |
Promise<ReadMedicalResourcesResponse> |
Paged medical resource read |
deleteMedicalResources(req) |
Promise<void> |
Delete by IDs or filters |
android-health-connect is built and maintained by Solution Forest. If you ship it in a production app, we can help with Health Connect integrations, custom record types, Play Console health declarations and long-term maintenance. Contact us through solutionforest.com.
Bug reports and feature requests go to GitHub Issues. For security issues, follow SECURITY.md.
MIT
Made with create-react-native-library
react-native health connect · android health connect react native · react native fitness data · steps, heart rate, sleep, exercise records · Health Connect permissions · Expo config plugin · TurboModule · wearables
