android-health-connect
npm GitHub
Docs · Reference

API reference

A condensed map of the exports. Full types ship with the package; the source of truth is src/index.tsx.

01Availability

FunctionReturnsDescription
isHealthConnectAvailable()Promise<HealthConnectAvailability>Whether Health Connect is usable
getHealthConnectAvailability()Promise<HealthConnectAvailabilityInfo>Detailed status and advice
openHealthConnectApp()voidOpen Health Connect or the Play Store
openHealthConnectSettings()voidOpen Health Connect settings
openHealthConnectDataManagement(pkg?)voidOpen permission management
checkLibraryUpdate(options?)Promise<LibraryUpdateInfo>Compare against GitHub Releases
LIBRARY_VERSIONstringInstalled package version

02Permissions & helpers

FunctionReturnsDescription
requestPermissions(perms)Promise<string[]>Show the permission dialog
checkPermissions(perms)Promise<string[]>Which are granted
hasPermissions(perms)Promise<boolean>True when all are granted
missingPermissions(perms)Promise<string[]>The subset not granted
ensurePermissions(perms, opts?)Promise<EnsurePermissionsResult>Request missing, then re-check
ensureAvailable(opts?)availabilityGate; opens the store when not installed
revokeAllPermissions()Promise<void>Revoke everything
Permission.*HealthPermissionTyped constants, e.g. Permission.READ_STEPS
timeRangeToday(), timeRangeLastDays(), timeRangeLastHours()TimeRangeFilterInstant windows
now() / HealthInstantISO Instant / rangeCarbon-style now().subHours(1).toISOString(), .until(now())
pollUntil, waitUntilresult / TSoft poll; waitUntil throws on timeout
useForegroundPoll, pollOnForegroundhook / controllerPoll on mount and on every resume
waitForRecords, readAllRecords, pullChangespaged helpersWait for rows, drain pages, changelog loop

03Records

FunctionDescription
readRecords<T>(type, options)Generic paged read
writeRecords(records)Insert
updateRecords(records)Update; needs metadata.id from a prior read
deleteRecordsByTime, deleteRecordsByIdDelete
aggregateRecord, aggregateGroupByDuration, aggregateGroupByPeriodTotals, Instant buckets, calendar buckets
getChangesToken, getChangesChangelog sync; tokens last about 30 days
requestExerciseRoute(recordId)Consent UI when a route is CONSENT_REQUIRED
readSteps, readHeartRate, …One helper per record type (42 types)

04React hooks

Each hook fetches on mount, on every foreground resume and when its arguments change, and ignores results after unmount. Data hooks return HealthQueryState<T>: { value, satisfied, loading, error, refresh }, and accept enabled, ready, timeoutMs and intervalMs. See the React hooks guide.

HookReturnsDescription
useHealthConnectAvailability(opts?)HealthQueryState<HealthConnectAvailability>Availability, re-checked on resume
useHealthConnectPermissions(perms, opts?)[HealthQueryState<EnsurePermissionsResult>, request]Granted / missing status, plus request() for the missing ones
useReadRecords<T>(type, opts?)HealthQueryState<ReadRecordsResponse<T>>One page of records; timeRangeFilter may be a function
useMostRecentRecord<T>(type, opts?)HealthQueryState<T | null>Newest record in the window (default: last 30 days)
useAggregate(type, range, opts?)HealthQueryState<AggregateResult>Aggregate metrics; range may be a function
useChanges(token, opts?)HealthQueryState<PullChangesResult>Changelog sync; continues from nextChangesToken, reports via onChanges

05Features, Matchmaking, PHR

Check getFeatureStatus before calling any of these.

FunctionDescription
getFeatureStatus(Feature.*)FeatureStatus.AVAILABLE or UNAVAILABLE
Feature / FeatureStatus / AvailabilityTyped constants (no hand-typed feature / status strings)
FhirVersion.R4PHR fhirVersion: { major: 4, minor: 0, patch: 1 }
checkIfMatchmakingIsPossible, launchMatchmakingMatchmaking UI
createMedicalDataSource, getMedicalDataSourcesFHIR data sources
upsertMedicalResources, readMedicalResources, deleteMedicalResourcesMedical resources