matinzd/react-native-health-connect
Tentang
Pustaka React Native untuk Health Connect (khusus Android).
Pengembangan web dan aplikasiYang dapat Anda lakukan
- Typescript :white_check_mark:
- New Architecture (TurboModule) :white_check_mark:
Pertumbuhan bintang terukur
- dalam 24 jam
- 0
- dalam 7 hari
- +1
- dalam 15 hari
- +1
- dalam 1 bulan
- Mengumpulkan riwayat
Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.
README.md
AsliThis library is a wrapper around Health Connect for react native. Health Connect is an Android API and platform. It unifies data from multiple devices and apps into an ecosystem. For Android developers, it provides a single interface for reading and writing a user’s health and fitness data. For Android users, it offers a place for control over which apps have read and/or write access to different types of data. Health Connect also provides on-device storage. Read more here.
Requirements
React Native 0.89 or higher is required. The library launches the Health Connect dialogs through ReactContext.registerForActivityResult, which React Native added in 0.89.
- Health Connect needs to be installed on the user's device. Starting from Android 14 (Upside Down Cake), Health Connect is part of the Android Framework. Read more here.
- Health Connect API requires
minSdkVersion=26(Android Oreo / 8.0). - Your app must use the React Native New Architecture, which is the default since React Native 0.76. If your app still uses the old architecture, stay on v4 of this library.
- If you are planning to release your app on Google Play, you must declare your Health Connect data access. This is now done in the Play Console — the standalone Google Form previously used for these requests is being retired on September 3rd, 2026, and all submissions go through the Play Console instead. See Google's health apps declaration guidance, or how to sign up for a Play Console developer account if you do not have one yet. Approval can take up to 7 days.
- Approval does not grant you immediate access to Health Connect. A whitelist must propagate to the Health Connect servers, which take an additional 5-7 business days. The whitelist is updated every Monday according to Google Fit AHP support.
Compatibility
| react-native-health-connect | React Native | MainActivity setup |
|---|---|---|
| 6.x | 0.89 or higher | None |
| 5.x | 0.76 or higher (New Architecture only) | HealthConnectPermissionDelegate.setPermissionDelegate(this) |
| 4.x | 0.71 or higher (latest patch) | HealthConnectPermissionDelegate.setPermissionDelegate(this) |
| 2.x – 3.x | 0.71 or higher | HealthConnectPermissionDelegate.setPermissionDelegate(this) |
If your app uses React Native 0.88 or lower, stay on 5.x. If it still uses the old architecture, stay on 4.x.
Installation
To install react-native-health-connect, use the following command:
npm install react-native-health-connect
No MainActivity changes are required. The library launches the permission dialogs on your app's existing ReactActivity, with no extra activity or manifest entry.
[!IMPORTANT] Breaking change in 6.0: React Native 0.89 or higher is required. If you are upgrading from 5.x or lower, remove the
HealthConnectPermissionDelegate.setPermissionDelegate(this)call from yourMainActivity. It is deprecated and does nothing. If you cannot upgrade React Native yet, stay on 5.x.
You also need to setup permissions in your AndroidManifest.xml file. For more information, check here.
Expo installation
This package cannot be used in the Expo Go app, but it can be used with custom managed apps.
[!NOTE] 6.x requires an Expo SDK that uses React Native 0.89 or higher. No stable Expo SDK does yet (SDK 58 uses React Native 0.88). Until one does, Expo apps must stay on 5.x.
As of v4, the Expo integration ships inside
react-native-health-connect. There is no longer a separateexpo-health-connectpackage to install — see Migrating fromexpo-health-connect.
Install the package with yarn, npm, or expo install:
npm install react-native-health-connect
npm install expo-build-properties --save-dev
Then add the config plugin to the plugins array of your app.json or app.config.js:
{
"expo": {
...
"plugins": [
"react-native-health-connect",
[
"expo-build-properties",
{
"android": {
"compileSdkVersion": 36,
"targetSdkVersion": 36,
"minSdkVersion": 26
}
}
]
]
...
}
}
Then rebuild the native app:
- Run
expo prebuild- This will apply the config plugin using prebuilding.
- Rebuild the app
yarn android-- Build on Android.
If the project doesn't build correctly with
yarn android, please file an issue and try setting the project up manually.
Finally create a new EAS development build
eas build --profile development --platform android
A complete working Expo app lives in example-expo/.
Migrating from expo-health-connect
expo-health-connect is deprecated; everything it did is now part of this package.
- Remove it:
npm uninstall expo-health-connect - In your
app.jsonpluginsarray, replace"expo-health-connect"with"react-native-health-connect". - Re-run
npx expo prebuild --clean.
Leaving expo-health-connect installed is not supported: both packages apply a config plugin to
the same manifest entries, and it still ships a native Expo module that this package no longer
needs.
Example
A quick example at a glance:
import {
initialize,
requestPermission,
readRecords,
} from 'react-native-health-connect';
const readSampleData = async () => {
// initialize the client
const isInitialized = await initialize();
// request permissions
const grantedPermissions = await requestPermission([
{ accessType: 'read', recordType: 'ActiveCaloriesBurned' },
]);
// check if granted
const result = await readRecords('ActiveCaloriesBurned', {
timeRangeFilter: {
operator: 'between',
startTime: '2023-01-09T12:00:00.405Z',
endTime: '2023-01-09T23:53:15.405Z',
},
});
// {
// result: [
// {
// startTime: '2023-01-09T12:00:00.405Z',
// endTime: '2023-01-09T23:53:15.405Z',
// energy: {
// inCalories: 15000000,
// inJoules: 62760000.00989097,
// inKilojoules: 62760.00000989097,
// inKilocalories: 15000,
// },
// metadata: {
// id: '239a8cfd-990d-42fc-bffc-c494b829e8e1',
// lastModifiedTime: '2023-01-17T21:06:23.335Z',
// clientRecordId: null,
// dataOrigin: 'com.healthconnectexample',
// clientRecordVersion: 0,
// device: 0,
// },
// },
// ],
// }
};
Alternatives
For iOS there are two alteranatives you can use which is very similar to Health Connect on Android. First one is @kingstinct/react-native-healthkit and the other one is react-native-health. These options are similar in functionality and can help you manage your health data on iOS.
Documentation
More examples and full documentation can be found here
Features
- Typescript :white_check_mark:
- New Architecture (TurboModule) :white_check_mark:
License
MIT
Jelajahi proyek terkait
Memuat…