Skip to content

Latest commit

 

History

History
146 lines (107 loc) · 6.09 KB

skills.md

File metadata and controls

146 lines (107 loc) · 6.09 KB
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.

android-health-connect

When to use

  • 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, …)

Do not

  • Invent APIs — only use exports from @solutionforest/android-health-connect (see published types / repo src/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()

Install

npmjs.org (primary)

yarn add @solutionforest/android-health-connect
# or: npm install @solutionforest/android-health-connect

No .npmrc required.

GitHub Packages (mirror)

# .npmrc
@solutionforest:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PAT

PAT: classic with read:packages (SSO for solutionforest if needed).

yarn add @solutionforest/android-health-connect

Same scoped name on both registries: @solutionforest/android-health-connect.

Version lines

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

Hard constraints

  • React Native ≥0.84, New Architecture / TurboModules
  • Android API 29+
  • Feature-gated APIs: call getFeatureStatus(Feature.*) and only proceed when FeatureStatus.AVAILABLE

Canonical implementation order

  1. Availability — getHealthConnectAvailability() / ensureAvailable(); open store with openHealthConnectApp() when needed.
  2. Permissions — ensurePermissions([Permission.READ_STEPS, ...]) (or requestPermissions / checkPermissions).
  3. Read — readSteps({ timeRangeFilter: timeRangeToday() }) or readRecords(RecordType.STEPS, …).
  4. 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.

  1. Write / update — writeRecords([{ recordType: RecordType.STEPS, … }]); updateRecords requires metadata.id from a prior read.
  2. Aggregates — aggregateRecord, aggregateGroupByDuration (Instant buckets), aggregateGroupByPeriod (calendar).
  3. Changelog — getChangesToken → getChanges / pullChanges (tokens ~30 days; prefer one record type per token).
  4. Matchmaking / PHR — only after feature status checks.

Expo

Add the config plugin, list only needed health permissions, then npx expo prebuild.

Bare RN

Declare the same health permissions in the host AndroidManifest.xml and add Health Connect rationale / intent-filters (see repo README).

Installing this skill

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.

References