| name | android-health-connect |
|---|---|
| description | Integrate Solution Forest's React Native TurboModule for Android Health Connect (@solutionforest/android-health-connect). Use when adding HC permissions, reading/writing health records, aggregates, changelog sync, React hooks, Matchmaking, PHR, Expo plugin setup, or choosing npmjs vs GitHub Packages. |
- Wiring Android Health Connect into a React Native / Expo app
- Choosing install source: npmjs.org (primary) or GitHub Packages (mirror)
- Implementing availability, permissions, records, aggregates, or resume polling
- Building React screens with the hooks (
useHealthConnectPermissions,useAggregate, …)
- Invent APIs — only use exports from
@solutionforest/android-health-connect(see published types / reposrc/index.tsx) - Target iOS — this library is Android-only
- Assume RN below 0.84 or Old Architecture
- Hand-type permission strings when
Permission.*exists - Hand-type record type strings when
RecordType.*exists (RecordType.STEPS, not'Steps') - Expect push/live updates from Health Connect — poll on resume
- Pass
timeRangeToday()(a new object each render) to a hook — pass() => timeRangeToday()
yarn add @solutionforest/android-health-connect
# or: npm install @solutionforest/android-health-connectNo .npmrc required.
# .npmrc
@solutionforest:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PATPAT: classic with read:packages (SSO for solutionforest if needed).
yarn add @solutionforest/android-health-connectSame scoped name on both registries: @solutionforest/android-health-connect.
| Line | HC SDK | AGP | compileSdk | Node |
|---|---|---|---|---|
0.3.x (default) |
1.2.0-alpha06 |
≥9.1 | 37 | ≥22.22 |
release-0.2 / 0.2.x |
1.1.0 stable |
≥8.9.1 | 36 | ≥22.11 |
- React Native ≥0.84, New Architecture / TurboModules
- Android API 29+
- Feature-gated APIs: call
getFeatureStatus(Feature.*)and only proceed whenFeatureStatus.AVAILABLE
- Availability —
getHealthConnectAvailability()/ensureAvailable(); open store withopenHealthConnectApp()when needed. - Permissions —
ensurePermissions([Permission.READ_STEPS, ...])(orrequestPermissions/checkPermissions). - Read —
readSteps({ timeRangeFilter: timeRangeToday() })orreadRecords(RecordType.STEPS, …). - Resume UX — first value after foreground is often
0/empty. Use:
import {
readSteps,
timeRangeToday,
useForegroundPoll,
} from '@solutionforest/android-health-connect';
const { value, loading, refresh } = useForegroundPoll(
() => readSteps({ timeRangeFilter: timeRangeToday() }),
{ ready: (r) => (r.records?.length ?? 0) > 0, timeoutMs: 15_000 },
);Non-React: pollOnForeground / pollUntil / waitUntil.
React components: prefer the typed hooks. They fetch on mount, on every resume and when their arguments change, and ignore results after unmount. Data hooks return { value, satisfied, loading, error, refresh } and accept enabled, ready, timeoutMs, intervalMs.
| Hook | value |
|---|---|
useHealthConnectAvailability() |
'available' | 'notInstalled' | 'notSupported' |
useHealthConnectPermissions(perms) |
[status, request]; status.value = { granted, missing, allGranted } |
useReadRecords<T>(RecordType.X, opts) |
ReadRecordsResponse<T> |
useMostRecentRecord<T>(RecordType.X, opts?) |
T | null |
useAggregate(RecordType.X, range, opts?) |
AggregateResult |
useChanges(token, { onChanges }) |
PullChangesResult; continues from nextChangesToken, persist it in onChanges |
const [perms, request] = useHealthConnectPermissions([Permission.READ_STEPS]);
const today = useAggregate(RecordType.STEPS, () => timeRangeToday(), {
enabled: perms.value?.allGranted === true,
ready: (r) => ((r.metrics['COUNT_TOTAL'] as number | null) ?? 0) > 0,
});Pass "now"-relative ranges as a function (() => timeRangeToday()), not timeRangeToday(): a function is re-evaluated per fetch, while a fresh object each render changes the arguments and refetches every render.
- Write / update —
writeRecords([{ recordType: RecordType.STEPS, … }]);updateRecordsrequiresmetadata.idfrom a prior read. - Aggregates —
aggregateRecord,aggregateGroupByDuration(Instant buckets),aggregateGroupByPeriod(calendar). - Changelog —
getChangesToken→getChanges/pullChanges(tokens ~30 days; prefer one record type per token). - Matchmaking / PHR — only after feature status checks.
Add the config plugin, list only needed health permissions, then npx expo prebuild.
Declare the same health permissions in the host AndroidManifest.xml and add Health Connect rationale / intent-filters (see repo README).
Save this file as SKILL.md in the project's skills folder, then commit it:
| Agent | Path |
|---|---|
| Cursor | .cursor/skills/android-health-connect/SKILL.md |
| Claude Code | .claude/skills/android-health-connect/SKILL.md |
| Others (Codex, Gemini CLI, …) | .agents/skills/android-health-connect/SKILL.md |
Source: node_modules/@solutionforest/android-health-connect/skills.md (matches the installed version) or https://solutionforest.github.io/AndroidHealthConnect/skills.md (latest). Re-copy after upgrading the package.
-
Skill install guide: https://solutionforest.github.io/AndroidHealthConnect/#agents
-
Docs: https://solutionforest.github.io/AndroidHealthConnect/
-
Install: https://solutionforest.github.io/AndroidHealthConnect/install.html
-
API: https://solutionforest.github.io/AndroidHealthConnect/api.html
-
npm: https://www.npmjs.com/package/@solutionforest/android-health-connect
-
GitHub Packages: https://github.com/orgs/solutionforest/packages?repo_name=AndroidHealthConnect
-
Source: https://github.com/solutionforest/AndroidHealthConnect