react-native-health-connect 3.6.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -18
- package/android-expo/build.gradle +53 -0
- package/android-expo/src/main/AndroidManifest.xml +2 -0
- package/android-expo/src/main/java/expo/modules/healthconnect/HealthConnectPackage.kt +11 -0
- package/android-expo/src/main/java/expo/modules/healthconnect/HealthConnectPermissionReactActivityHandler.kt +15 -0
- package/app.plugin.js +81 -14
- package/expo-module.config.json +8 -0
- package/package.json +23 -7
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ Make sure you have React Native version 0.71 or higher **with the latest patch**
|
|
|
23
23
|
|
|
24
24
|
- [Health Connect](https://play.google.com/store/apps/details?id=com.google.android.apps.healthdata&hl=en&gl=US) 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](https://developer.android.com/health-and-fitness/guides/health-connect/develop/get-started#step-1).
|
|
25
25
|
- Health Connect API requires `minSdkVersion=26` (Android Oreo / 8.0).
|
|
26
|
-
- If you are planning to release your app on Google Play, you
|
|
26
|
+
- 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](https://play.google.com/apps/publish/signup) — 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](https://support.google.com/googleplay/android-developer/answer/14738291?hl=en), or [how to sign up for a Play Console developer account](https://support.google.com/googleplay/android-developer/answer/6112435?hl=en#zippy=%2Cstep-sign-up-for-a-play-console-developer-account) if you do not have one yet. Approval can take up to 7 days.
|
|
27
27
|
- 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.
|
|
28
28
|
|
|
29
29
|
## Installation
|
|
@@ -74,40 +74,34 @@ You also need to setup permissions in your `AndroidManifest.xml` file. For more
|
|
|
74
74
|
## Expo installation
|
|
75
75
|
|
|
76
76
|
This package cannot be used in the [Expo Go](https://expo.io/client) app, but it can be used with custom managed apps.
|
|
77
|
-
Just add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`:
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
> **As of v4, the Expo integration ships inside `react-native-health-connect`.** There is no longer
|
|
79
|
+
> a separate `expo-health-connect` package to install — see [Migrating from
|
|
80
|
+
> `expo-health-connect`](#migrating-from-expo-health-connect).
|
|
81
|
+
|
|
82
|
+
Install the package with yarn, npm, or [`expo install`](https://docs.expo.io/workflow/expo-cli/#expo-install):
|
|
80
83
|
|
|
81
84
|
```sh
|
|
82
|
-
npm install
|
|
85
|
+
npm install react-native-health-connect
|
|
83
86
|
npm install expo-build-properties --save-dev
|
|
84
87
|
```
|
|
85
88
|
|
|
86
|
-
Then add the
|
|
87
|
-
|
|
88
|
-
```json
|
|
89
|
-
{
|
|
90
|
-
"expo": {
|
|
91
|
-
"plugins": ["expo-health-connect"]
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
- Edit your app.json again and add this
|
|
89
|
+
Then add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`:
|
|
97
90
|
|
|
98
91
|
```json
|
|
99
92
|
{
|
|
100
93
|
"expo": {
|
|
101
94
|
...
|
|
102
95
|
"plugins": [
|
|
96
|
+
"react-native-health-connect",
|
|
103
97
|
[
|
|
104
98
|
"expo-build-properties",
|
|
105
99
|
{
|
|
106
100
|
"android": {
|
|
107
|
-
"compileSdkVersion":
|
|
108
|
-
"targetSdkVersion":
|
|
101
|
+
"compileSdkVersion": 36,
|
|
102
|
+
"targetSdkVersion": 36,
|
|
109
103
|
"minSdkVersion": 26
|
|
110
|
-
}
|
|
104
|
+
}
|
|
111
105
|
}
|
|
112
106
|
]
|
|
113
107
|
]
|
|
@@ -116,6 +110,10 @@ Then add the prebuild [config plugin](https://docs.expo.io/guides/config-plugins
|
|
|
116
110
|
}
|
|
117
111
|
```
|
|
118
112
|
|
|
113
|
+
You do **not** need to touch `MainActivity` in an Expo project. The permission delegate shown in the
|
|
114
|
+
React Native CLI section above is registered automatically by the Expo module bundled with this
|
|
115
|
+
package.
|
|
116
|
+
|
|
119
117
|
Then rebuild the native app:
|
|
120
118
|
|
|
121
119
|
- Run `expo prebuild`
|
|
@@ -129,6 +127,20 @@ Finally create a new EAS development build
|
|
|
129
127
|
|
|
130
128
|
`eas build --profile development --platform android`
|
|
131
129
|
|
|
130
|
+
A complete working Expo app lives in [`example-expo/`](./example-expo).
|
|
131
|
+
|
|
132
|
+
### Migrating from `expo-health-connect`
|
|
133
|
+
|
|
134
|
+
`expo-health-connect` is deprecated; everything it did is now part of this package.
|
|
135
|
+
|
|
136
|
+
1. Remove it: `npm uninstall expo-health-connect`
|
|
137
|
+
2. In your `app.json` `plugins` array, replace `"expo-health-connect"` with `"react-native-health-connect"`.
|
|
138
|
+
3. Re-run `npx expo prebuild --clean`.
|
|
139
|
+
|
|
140
|
+
If you leave `expo-health-connect` installed, the Android build fails with a duplicate
|
|
141
|
+
`expo.modules.healthconnect.HealthConnectPackage` class — both packages contribute the same Kotlin
|
|
142
|
+
class. Removing the old package resolves it.
|
|
143
|
+
|
|
132
144
|
## Example
|
|
133
145
|
|
|
134
146
|
A quick example at a glance:
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
|
|
3
|
+
// Read from package.json so it tracks the library and cannot drift. Without this,
|
|
4
|
+
// Expo autolinking reports the module as "react-native-health-connect-expo
|
|
5
|
+
// (unspecified)" in its module list.
|
|
6
|
+
group = 'expo.modules.healthconnect'
|
|
7
|
+
version = new groovy.json.JsonSlurper().parseText(file('../package.json').text).version
|
|
8
|
+
|
|
9
|
+
// This project is only ever included by Expo autolinking. Bare React Native projects
|
|
10
|
+
// never add it to their settings.gradle, so `expo-modules-core` is guaranteed to be
|
|
11
|
+
// on the classpath whenever this file is evaluated.
|
|
12
|
+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
13
|
+
apply from: expoModulesCorePlugin
|
|
14
|
+
applyKotlinExpoModulesCorePlugin()
|
|
15
|
+
useCoreDependencies()
|
|
16
|
+
|
|
17
|
+
// If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
|
|
18
|
+
def useManagedAndroidSdkVersions = false
|
|
19
|
+
if (useManagedAndroidSdkVersions) {
|
|
20
|
+
useDefaultAndroidSdkVersions()
|
|
21
|
+
} else {
|
|
22
|
+
buildscript {
|
|
23
|
+
// Simple helper that allows the root project to override versions declared by this library.
|
|
24
|
+
ext.safeExtGet = { prop, fallback ->
|
|
25
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
project.android {
|
|
29
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 36)
|
|
30
|
+
defaultConfig {
|
|
31
|
+
minSdkVersion safeExtGet("minSdkVersion", 26)
|
|
32
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 36)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
android {
|
|
38
|
+
namespace "expo.modules.healthconnect"
|
|
39
|
+
lintOptions {
|
|
40
|
+
abortOnError false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
dependencies {
|
|
45
|
+
implementation project(':expo-modules-core')
|
|
46
|
+
// Provides dev.matinzd.healthconnect.permissions.HealthConnectPermissionDelegate.
|
|
47
|
+
// Linked into the same settings.gradle by React Native autolinking.
|
|
48
|
+
implementation project(':react-native-health-connect')
|
|
49
|
+
|
|
50
|
+
//noinspection GradleDynamicVersion
|
|
51
|
+
implementation 'com.facebook.react:react-native:+'
|
|
52
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:${safeExtGet('kotlinVersion', '1.8.10')}"
|
|
53
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
package expo.modules.healthconnect
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import expo.modules.core.interfaces.Package
|
|
5
|
+
import expo.modules.core.interfaces.ReactActivityLifecycleListener
|
|
6
|
+
|
|
7
|
+
class HealthConnectPackage : Package {
|
|
8
|
+
override fun createReactActivityLifecycleListeners(activityContext: Context?): MutableList<out ReactActivityLifecycleListener> {
|
|
9
|
+
return mutableListOf(HealthConnectPermissionReactActivityHandler())
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package expo.modules.healthconnect
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.os.Bundle
|
|
5
|
+
import com.facebook.react.ReactActivity
|
|
6
|
+
import dev.matinzd.healthconnect.permissions.HealthConnectPermissionDelegate
|
|
7
|
+
import expo.modules.core.interfaces.ReactActivityLifecycleListener
|
|
8
|
+
|
|
9
|
+
class HealthConnectPermissionReactActivityHandler : ReactActivityLifecycleListener {
|
|
10
|
+
override fun onCreate(activity: Activity?, savedInstanceState: Bundle?) {
|
|
11
|
+
super.onCreate(activity, savedInstanceState)
|
|
12
|
+
val reactActivity = activity as? ReactActivity ?: return
|
|
13
|
+
HealthConnectPermissionDelegate.setPermissionDelegate(reactActivity)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/app.plugin.js
CHANGED
|
@@ -1,21 +1,88 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {
|
|
2
|
+
AndroidConfig,
|
|
3
|
+
createRunOncePlugin,
|
|
4
|
+
withAndroidManifest,
|
|
5
|
+
} = require('@expo/config-plugins');
|
|
2
6
|
|
|
3
|
-
const
|
|
4
|
-
return withAndroidManifest(config, async (config) => {
|
|
5
|
-
let androidManifest = config.modResults.manifest;
|
|
7
|
+
const pkg = require('./package.json');
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const { getMainActivityOrThrow, getMainApplicationOrThrow } =
|
|
10
|
+
AndroidConfig.Manifest;
|
|
11
|
+
|
|
12
|
+
const RATIONALE_ACTION = 'androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE';
|
|
13
|
+
const VIEW_PERMISSION_USAGE_ALIAS = 'ViewPermissionUsageActivity';
|
|
14
|
+
|
|
15
|
+
const hasIntentFilter = (androidName, intentFilters) =>
|
|
16
|
+
intentFilters.some((intentFilter) =>
|
|
17
|
+
(intentFilter.action || []).some(
|
|
18
|
+
(action) => action.$['android:name'] === androidName
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const hasActivityAlias = (androidName, activityAliases) =>
|
|
23
|
+
activityAliases.some(
|
|
24
|
+
(activityAlias) => activityAlias.$['android:name'] === androidName
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const withHealthConnect = (config) =>
|
|
28
|
+
withAndroidManifest(config, async (config) => {
|
|
29
|
+
const mainApplication = getMainApplicationOrThrow(config.modResults);
|
|
30
|
+
const mainActivity = getMainActivityOrThrow(config.modResults);
|
|
31
|
+
|
|
32
|
+
// Through Android 13, the main activity handles the intent shown when users tap
|
|
33
|
+
// the privacy policy link in the Health Connect permission dialog.
|
|
34
|
+
if (!mainActivity['intent-filter']) {
|
|
35
|
+
mainActivity['intent-filter'] = [];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!hasIntentFilter(RATIONALE_ACTION, mainActivity['intent-filter'])) {
|
|
39
|
+
mainActivity['intent-filter'].push({
|
|
40
|
+
action: [{ $: { 'android:name': RATIONALE_ACTION } }],
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Starting with Android 14 the same rationale is reached through an activity
|
|
45
|
+
// alias guarded by START_VIEW_PERMISSION_USAGE instead.
|
|
46
|
+
if (!mainApplication['activity-alias']) {
|
|
47
|
+
mainApplication['activity-alias'] = [];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (
|
|
51
|
+
!hasActivityAlias(
|
|
52
|
+
VIEW_PERMISSION_USAGE_ALIAS,
|
|
53
|
+
mainApplication['activity-alias']
|
|
54
|
+
)
|
|
55
|
+
) {
|
|
56
|
+
mainApplication['activity-alias'].push({
|
|
57
|
+
$: {
|
|
58
|
+
'android:name': VIEW_PERMISSION_USAGE_ALIAS,
|
|
59
|
+
'android:exported': 'true',
|
|
60
|
+
'android:targetActivity': mainActivity.$['android:name'],
|
|
61
|
+
'android:permission':
|
|
62
|
+
'android.permission.START_VIEW_PERMISSION_USAGE',
|
|
13
63
|
},
|
|
14
|
-
|
|
15
|
-
|
|
64
|
+
'intent-filter': [
|
|
65
|
+
{
|
|
66
|
+
action: [
|
|
67
|
+
{
|
|
68
|
+
$: {
|
|
69
|
+
'android:name': 'android.intent.action.VIEW_PERMISSION_USAGE',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
category: [
|
|
74
|
+
{
|
|
75
|
+
$: {
|
|
76
|
+
'android:name': 'android.intent.category.HEALTH_PERMISSIONS',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
16
84
|
|
|
17
85
|
return config;
|
|
18
86
|
});
|
|
19
|
-
};
|
|
20
87
|
|
|
21
|
-
module.exports = withHealthConnect;
|
|
88
|
+
module.exports = createRunOncePlugin(withHealthConnect, pkg.name, pkg.version);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-health-connect",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "React native library for health connect (Android only)",
|
|
5
5
|
"funding": "https://github.com/matinzd/react-native-health-connect?sponsor=1",
|
|
6
6
|
"main": "lib/commonjs/index",
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"android": "yarn workspace example android",
|
|
25
25
|
"start": "yarn workspace example start",
|
|
26
|
+
"expo-example": "yarn workspace example-expo",
|
|
27
|
+
"expo-example:android": "yarn workspace example-expo android",
|
|
26
28
|
"test": "jest",
|
|
27
29
|
"typecheck": "tsc --noEmit",
|
|
28
30
|
"lint": "eslint ./src",
|
|
@@ -35,11 +37,13 @@
|
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"@commitlint/config-conventional": "^17.4.2",
|
|
37
39
|
"@evilmartians/lefthook": "^1.2.8",
|
|
40
|
+
"@expo/config-plugins": "~57.0.6",
|
|
38
41
|
"@react-native-community/eslint-config": "^3.0.2",
|
|
39
|
-
"@react-native/babel-preset": "0.
|
|
42
|
+
"@react-native/babel-preset": "0.86.2",
|
|
43
|
+
"@react-native/jest-preset": "0.86.2",
|
|
40
44
|
"@release-it/conventional-changelog": "^5.1.1",
|
|
41
45
|
"@types/jest": "^28.1.2",
|
|
42
|
-
"@types/react": "~
|
|
46
|
+
"@types/react": "~19.2.0",
|
|
43
47
|
"commitlint": "^17.4.2",
|
|
44
48
|
"eslint": "^8.4.1",
|
|
45
49
|
"eslint-config-prettier": "^8.5.0",
|
|
@@ -47,8 +51,8 @@
|
|
|
47
51
|
"husky": "^8.0.3",
|
|
48
52
|
"jest": "^29.6.3",
|
|
49
53
|
"prettier": "^2.8.4",
|
|
50
|
-
"react": "19.
|
|
51
|
-
"react-native": "0.
|
|
54
|
+
"react": "19.2.3",
|
|
55
|
+
"react-native": "0.86.2",
|
|
52
56
|
"react-native-builder-bob": "^0.20.0",
|
|
53
57
|
"react-native-monorepo-config": "^0.1.9",
|
|
54
58
|
"release-it": "^15.11.0",
|
|
@@ -65,8 +69,11 @@
|
|
|
65
69
|
"src",
|
|
66
70
|
"lib",
|
|
67
71
|
"android",
|
|
72
|
+
"android-expo",
|
|
73
|
+
"expo-module.config.json",
|
|
68
74
|
"!lib/typescript/example",
|
|
69
75
|
"!android/build",
|
|
76
|
+
"!android-expo/build",
|
|
70
77
|
"!android/gradle",
|
|
71
78
|
"!android/gradlew",
|
|
72
79
|
"!android/gradlew.bat",
|
|
@@ -78,19 +85,28 @@
|
|
|
78
85
|
"app.plugin.js"
|
|
79
86
|
],
|
|
80
87
|
"resolutions": {
|
|
81
|
-
"@types/react": "
|
|
88
|
+
"@types/react": "19.2.0"
|
|
82
89
|
},
|
|
83
90
|
"peerDependencies": {
|
|
84
91
|
"@expo/config-plugins": ">= 6.0.2",
|
|
92
|
+
"expo": "*",
|
|
85
93
|
"react": "*",
|
|
86
94
|
"react-native": "*"
|
|
87
95
|
},
|
|
96
|
+
"peerDependenciesMeta": {
|
|
97
|
+
"@expo/config-plugins": {
|
|
98
|
+
"optional": true
|
|
99
|
+
},
|
|
100
|
+
"expo": {
|
|
101
|
+
"optional": true
|
|
102
|
+
}
|
|
103
|
+
},
|
|
88
104
|
"engines": {
|
|
89
105
|
"node": ">= 16.0.0"
|
|
90
106
|
},
|
|
91
107
|
"packageManager": "yarn@4.9.4",
|
|
92
108
|
"jest": {
|
|
93
|
-
"preset": "react-native",
|
|
109
|
+
"preset": "@react-native/jest-preset",
|
|
94
110
|
"modulePathIgnorePatterns": [
|
|
95
111
|
"<rootDir>/example/node_modules",
|
|
96
112
|
"<rootDir>/lib/"
|