Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new expo plugin #110

Merged
merged 3 commits into from
Jun 30, 2024
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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
This 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](https://developer.android.com/guide/health-and-fitness/health-connect).

## Requirements

Make sure you have React Native version 0.71 or higher installed to use v2 of React Native Health Connect.

- [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).
Expand All @@ -30,10 +31,10 @@ Make sure you have React Native version 0.71 or higher installed to use v2 of Re
To install react-native-health-connect, use the following command:

```bash
yarn add react-native-health-connect
npm install react-native-health-connect
```

For version 2 onwards, please add the following code into your `MainActivity.kt` within the `onCreate` method:
If you are using React Native CLI template, for version 2 onwards, please add the following code into your `MainActivity.kt` within the `onCreate` method:

```diff
package com.healthconnectexample
Expand Down Expand Up @@ -68,6 +69,7 @@ class MainActivity : ReactActivity() {

```

You also need to setup permissions in your `AndroidManifest.xml` file. For more information, check [here](https://matinzd.github.io/react-native-health-connect/docs/permissions).

## Expo installation

Expand All @@ -77,15 +79,15 @@ Just add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the
First install the package with yarn, npm, or [`expo install`](https://docs.expo.io/workflow/expo-cli/#expo-install).

```sh
expo install react-native-health-connect
npm install expo-health-connect expo-build-properties --save-dev
```

Then add the prebuild [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`:

```json
{
"expo": {
"plugins": ["react-native-health-connect"]
"plugins": ["expo-health-connect"]
}
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.matinzd.healthconnect.permissions

import androidx.activity.ComponentActivity
import androidx.activity.result.ActivityResultLauncher
import androidx.health.connect.client.PermissionController
import com.facebook.react.ReactActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
Expand All @@ -15,7 +15,7 @@ object HealthConnectPermissionDelegate {
private val coroutineScope = CoroutineScope(Dispatchers.IO)

fun setPermissionDelegate(
activity: ReactActivity,
activity: ComponentActivity,
providerPackageName: String = "com.google.android.apps.healthdata"
) {
val contract = PermissionController.createRequestPermissionResultContract(providerPackageName)
Expand Down
12 changes: 7 additions & 5 deletions docs/docs/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ title: Get started

## Requirements

Make sure you have React Native version 0.71 or higher installed to use v2 of React Native Health Connect.

- [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).
- Health Connect API requires `minSdkVersion=26` (Android Oreo / 8.0).
- If you are planning to release your app on Google Play, you will need to submit a [declaration form](https://docs.google.com/forms/d/1LFjbq1MOCZySpP5eIVkoyzXTanpcGTYQH26lKcrQUJo/viewform?edit_requested=true). Approval can take up to 7 days.
Expand All @@ -23,10 +25,10 @@ Health Connect requires the user to have screen lock enabled with a PIN, pattern
To install react-native-health-connect, use the following command:

```bash
yarn add react-native-health-connect
npm install react-native-health-connect
```

For version 2 onwards, please add the following code into your `MainActivity.kt` within the `onCreate` method:
If you are using React Native CLI template, for version 2 onwards, please add the following code into your `MainActivity.kt` within the `onCreate` method:

```diff
package com.healthconnectexample
Expand Down Expand Up @@ -60,7 +62,7 @@ class MainActivity : ReactActivity() {
}

```

You also need to setup permissions in your `AndroidManifest.xml` file. For more information, check [here](https://matinzd.github.io/react-native-health-connect/docs/permissions).

## Expo installation

Expand All @@ -70,15 +72,15 @@ Just add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the
First install the package with yarn, npm, or [`expo install`](https://docs.expo.io/workflow/expo-cli/#expo-install).

```sh
expo install react-native-health-connect
npm install expo-health-connect expo-build-properties --save-dev
```

Then add the prebuild [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`:

```json
{
"expo": {
"plugins": ["react-native-health-connect"]
"plugins": ["expo-health-connect"]
}
}
```
Expand Down
50 changes: 26 additions & 24 deletions docs/docs/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Permissions

# Permissions

## Setting up permissions
## Setting up permissions in React Native CLI template

To access health data from the Health Connect app in your own app, you need to add the necessary permissions and filters to the app manifest.

Expand Down Expand Up @@ -64,31 +64,33 @@ class PermissionsRationaleActivity: AppCompatActivity() {
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
// highlight-start
<!-- For supported versions through Android 13, create an activity to show the rationale
of Health Connect permissions once users click the privacy policy link. -->
<activity
android:name=".PermissionsRationaleActivity"
android:exported="true">
<intent-filter>
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>
+ <!-- For supported versions through Android 13, create an activity to show the rationale
+ of Health Connect permissions once users click the privacy policy link. -->
+ <intent-filter>
+ <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
+ </intent-filter>
</activity>

<!-- For versions starting Android 14, create an activity alias to show the rationale
of Health Connect permissions once users click the privacy policy link. -->
<activity-alias
android:name="ViewPermissionUsageActivity"
android:exported="true"
android:targetActivity=".PermissionsRationaleActivity"
android:permission="android.permission.START_VIEW_PERMISSION_USAGE">
<intent-filter>
<action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
<category android:name="android.intent.category.HEALTH_PERMISSIONS" />
</intent-filter>
</activity-alias>
// highlight-end
+ <activity
+ android:name=".PermissionsRationaleActivity"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
+ </intent-filter>
+ </activity>
+
+ <!-- For versions starting Android 14, create an activity alias to show the rationale
+ of Health Connect permissions once users click the privacy policy link. -->
+ <activity-alias
+ android:name="ViewPermissionUsageActivity"
+ android:exported="true"
+ android:targetActivity=".MainActivity"
+ android:permission="android.permission.START_VIEW_PERMISSION_USAGE">
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
+ <category android:name="android.intent.category.HEALTH_PERMISSIONS" />
+ </intent-filter>
+ </activity-alias>
```


Expand Down
9 changes: 2 additions & 7 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- For supported versions through Android 13, create an activity to show the rationale
<!-- For supported versions through Android 13, create an activity to show the rationale
of Health Connect permissions once users click the privacy policy link. -->
<activity
android:name=".PermissionsRationaleActivity"
android:exported="true">
<intent-filter>
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>
Expand All @@ -39,7 +34,7 @@
<activity-alias
android:name="ViewPermissionUsageActivity"
android:exported="true"
android:targetActivity=".PermissionsRationaleActivity"
android:targetActivity=".MainActivity"
android:permission="android.permission.START_VIEW_PERMISSION_USAGE">
<intent-filter>
<action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
Expand Down

This file was deleted.

Loading