android-health-connect
npm GitHub
Docs · Quickstart

Quickstart

After you install the package, wire up availability, then permissions, then reads.

01Check availability

Health Connect is built into Android 14+, and is a Play Store app on Android 9–13. Check before anything else.

availability.ts
import {
  getHealthConnectAvailability,
  openHealthConnectApp,
} from '@solutionforest/android-health-connect';

const info = await getHealthConnectAvailability();
if (info.status === 'notInstalled') {
  openHealthConnectApp(); // opens Health Connect or the Play Store
}
statusMeaning
'available'Installed and ready
'notInstalled'The Health Connect app needs installing or updating
'notSupported'OS too old, no Google Play services, or otherwise unusable

02Request permissions

Use the typed Permission.* constants rather than hand-typed strings. ensurePermissions requests only what is missing, then re-checks.

permissions.ts
import {
  Permission,
  ensurePermissions,
} from '@solutionforest/android-health-connect';

const { allGranted, missing } = await ensurePermissions([
  Permission.READ_STEPS,
  Permission.WRITE_STEPS,
]);

03Read records

Every record type has a helper such as readSteps. Results are paged with pageToken.

read.ts
import {
  readSteps,
  timeRangeToday,
} from '@solutionforest/android-health-connect';

const { records, pageToken } = await readSteps({
  timeRangeFilter: timeRangeToday(),
});

04Poll on resume

Health Connect has no push observer. When the app resumes, the first read is often empty until Samsung Health, Fitbit, and others finish syncing. useForegroundPoll polls on mount and on every resume until ready passes.

TodaySteps.tsx
import {
  readSteps,
  timeRangeToday,
  useForegroundPoll,
} from '@solutionforest/android-health-connect';

const { value, satisfied, loading, refresh } = useForegroundPoll(
  () => readSteps({ timeRangeFilter: timeRangeToday() }),
  {
    ready: (r) => r.records.length > 0,
    timeoutMs: 15_000,
  },
);

satisfied: false means the timeout hit before ready passed. The value may be a real zero, so show it as stale rather than as an error. Outside React, use pollOnForeground, pollUntil, or waitUntil.

05Expo

SDK 50+. Add the config plugin with only the permissions you need, then run npx expo prebuild.

app.json
{
  "expo": {
    "plugins": [
      [
        "@solutionforest/android-health-connect",
        {
          "permissions": [
            "android.permission.health.READ_STEPS",
            "android.permission.health.WRITE_STEPS"
          ]
        }
      ]
    ]
  }
}

06Bare React Native

Declare every health permission in your app's manifest (the library manifest merges in, but Health Connect checks the host app), and add the two intent filters Health Connect uses to show your permission rationale.

android/app/src/main/AndroidManifest.xml
<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" />

  <application ...>
    <activity android:name=".MainActivity" ...>
      <!-- Permission rationale (Android 13 and below) -->
      <intent-filter>
        <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
      </intent-filter>

      <!-- Permission usage screen (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>
android/app/src/main/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>

Then match AGP and compileSdk to the line you installed (0.3.x or 0.2.x).

Next: the usage guides cover writes, updates, deletes, aggregates, changelog sync, exercise routes, Matchmaking, PHR, and common mistakes.