Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Typecheck files
run: yarn typecheck

- name: Typecheck Expo example
run: yarn example:expo typecheck

test:
runs-on: ubuntu-latest

Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,22 @@ your app needs:

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](https://docs.expo.dev/develop/development-builds/introduction/):

```sh
npx expo install expo-dev-client
npx expo prebuild --platform android
npx expo run:android
```

The library needs `minSdkVersion` 29. If your app targets lower, raise it with
[`expo-build-properties`](https://docs.expo.dev/versions/latest/sdk/build-properties/).

For a working setup, see the **[Expo example app](example-expo/)** (Expo SDK 58,
dev client, config plugin). It checks availability, requests permission, reads
the last 7 days of steps and aggregates them.

### Android setup (bare React Native)

#### 1. Declare permissions in your app's `AndroidManifest.xml`
Expand Down
45 changes: 43 additions & 2 deletions docs/install.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h4>On this page</h4>
<a href="#registries">Registries</a>
<a href="#versions">Version lines</a>
<a href="#requirements">Requirements</a>
<a href="#expo">Expo</a>
<a href="#ai-skill">AI agent skill</a>
<a href="#alternatives">Alternatives</a>
</nav>
Expand Down Expand Up @@ -182,8 +183,48 @@ <h2><span class="step">03</span>Requirements for 0.3.x</h2>
</div>
</section>

<section id="expo">
<h2><span class="step">04</span>Expo</h2>
<p>
Add the config plugin to <code>app.json</code> and list the permissions
your app uses. On prebuild it writes them, plus the Health Connect intent
filters, into <code>AndroidManifest.xml</code>.
</p>
<div class="code">
<div class="code__bar"><span>app.json</span><button class="copy" data-copy>Copy</button></div>
<pre><code>{
"expo": {
"plugins": [
"expo-dev-client",
["expo-build-properties", { "android": { "minSdkVersion": 29 } }],
[
"@solutionforest/android-health-connect",
{ "permissions": ["android.permission.health.READ_STEPS"] }
]
]
}
}</code></pre>
</div>
<p>
Health Connect is a native module, so it does not run in Expo Go. Build a
development client instead:
</p>
<div class="code">
<div class="code__bar"><span>terminal</span><button class="copy" data-copy>Copy</button></div>
<pre><code>npx expo install expo-dev-client expo-build-properties
npx expo prebuild --platform android
npx expo run:android</code></pre>
</div>
<p>
The
<a href="https://github.com/solutionforest/AndroidHealthConnect/tree/main/example-expo">Expo example app</a>
(Expo SDK 58, React Native 0.88) shows the full flow: availability,
permission request, the last 7 days of steps, and an aggregate.
</p>
</section>

<section id="ai-skill">
<h2><span class="step">04</span>Install the AI agent skill</h2>
<h2><span class="step">05</span>Install the AI agent skill</h2>
<p>
The package includes <code>skills.md</code>, a skill file that tells
coding agents how to use this library: which version line to pick, the
Expand Down Expand Up @@ -230,7 +271,7 @@ <h2><span class="step">04</span>Install the AI agent skill</h2>
</section>

<section id="alternatives">
<h2><span class="step">05</span>Alternatives</h2>
<h2><span class="step">06</span>Alternatives</h2>
<ul>
<li>Git: <code>solutionforest/AndroidHealthConnect#v0.3.17</code></li>
<li>
Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export default defineConfig([
'plugin/build/',
'.github/scripts/',
'example/',
'example-expo/',
'coverage/',
],
},
Expand Down
4 changes: 4 additions & 0 deletions example-expo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by `npx expo prebuild` — never commit.
android/
ios/
.expo/
58 changes: 58 additions & 0 deletions example-expo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Android Health Connect — Expo example

A minimal [Expo](https://docs.expo.dev/) app that uses
[`@solutionforest/android-health-connect`](../README.md) through its config
plugin. It shows the usual flow:

1. Check Health Connect availability.
2. Request the `READ_STEPS` permission.
3. Read the last 7 days of step records.
4. Aggregate the step total for the same range.

The bare React Native example in [`../example`](../example) covers the rest of
the API.

Health Connect is a native module, so this app needs a
[development build](https://docs.expo.dev/develop/development-builds/introduction/).
It does not run in Expo Go.

## Versions

- Expo SDK 58 (React Native 0.88)
- `minSdkVersion` 29, set with `expo-build-properties`

## Run

You need the [Android toolchain](https://docs.expo.dev/get-started/set-up-your-environment/?platform=android&device=physical&mode=development-build&buildEnv=local)
and a device or emulator with Google Play, so Health Connect can be installed.

```sh
# from the repo root
yarn # install all workspaces
yarn prepare # build the library and its config plugin

cd example-expo
npx expo prebuild --platform android # generate android/ from app.json
npx expo run:android # build, install and start the dev client
```

`android/` is generated, so it is git-ignored. Run `npx expo prebuild --clean`
after you change `app.json`.

## How the config plugin is set up

`app.json` registers the plugin and lists the permissions the app declares:

```json
[
"@solutionforest/android-health-connect",
{ "permissions": ["android.permission.health.READ_STEPS"] }
]
```

On prebuild, the plugin writes those `<uses-permission>` entries and the Health
Connect intent filters into `AndroidManifest.xml`. Keep the list in sync with
what the app requests at runtime (`PERMISSIONS` in `src/App.tsx`).

`metro.config.js` points Metro at the library source in this repo. A normal
Expo app installs the package from npm and does not need it.
29 changes: 29 additions & 0 deletions example-expo/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"expo": {
"name": "Health Connect Expo Example",
"slug": "android-health-connect-expo-example",
"version": "0.0.1",
"orientation": "portrait",
"platforms": ["android"],
"android": {
"package": "com.solutionforest.healthconnect.expoexample"
},
"plugins": [
"expo-dev-client",
[
"expo-build-properties",
{
"android": {
"minSdkVersion": 29
}
}
],
[
"@solutionforest/android-health-connect",
{
"permissions": ["android.permission.health.READ_STEPS"]
}
]
]
}
}
5 changes: 5 additions & 0 deletions example-expo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { registerRootComponent } from 'expo';

import App from './src/App';

registerRootComponent(App);
16 changes: 16 additions & 0 deletions example-expo/metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const path = require('path');
const { getDefaultConfig } = require('expo/metro-config');
const { withMetroConfig } = require('react-native-monorepo-config');

const root = path.resolve(__dirname, '..');

/**
* Resolves `@solutionforest/android-health-connect` to the library source in
* this repo. A normal Expo app does not need this file.
*
* @type {import('expo/metro-config').MetroConfig}
*/
module.exports = withMetroConfig(getDefaultConfig(__dirname), {
root,
dirname: __dirname,
});
29 changes: 29 additions & 0 deletions example-expo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "android-health-connect-expo-example",
"version": "0.0.1",
"private": true,
"main": "index.ts",
"scripts": {
"start": "expo start --dev-client",
"prebuild": "expo prebuild --platform android",
"android": "expo run:android",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@solutionforest/android-health-connect": "workspace:*",
"expo": "~58.0.26",
"expo-build-properties": "~58.0.12",
"expo-dev-client": "~58.0.21",
"expo-status-bar": "~58.0.5",
"react": "19.3.1",
"react-native": "0.88.1"
},
"devDependencies": {
"@types/react": "^19.2.0",
"react-native-monorepo-config": "^0.4.0",
"typescript": "^5.9.2"
},
"engines": {
"node": ">=22.11.0"
}
}
Loading