diff --git a/README.md b/README.md index 9d35970..33cbb65 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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 @@ -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 @@ -77,7 +79,7 @@ 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`: @@ -85,7 +87,7 @@ Then add the prebuild [config plugin](https://docs.expo.io/guides/config-plugins ```json { "expo": { - "plugins": ["react-native-health-connect"] + "plugins": ["expo-health-connect"] } } ``` diff --git a/android/src/main/java/dev/matinzd/healthconnect/permissions/HealthConnectPermissionDelegate.kt b/android/src/main/java/dev/matinzd/healthconnect/permissions/HealthConnectPermissionDelegate.kt index 0db6a04..a6b6ed4 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/permissions/HealthConnectPermissionDelegate.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/permissions/HealthConnectPermissionDelegate.kt @@ -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 @@ -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) diff --git a/docs/docs/get-started.md b/docs/docs/get-started.md index 1bcea05..d168141 100644 --- a/docs/docs/get-started.md +++ b/docs/docs/get-started.md @@ -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. @@ -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 @@ -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 @@ -70,7 +72,7 @@ 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`: @@ -78,7 +80,7 @@ Then add the prebuild [config plugin](https://docs.expo.io/guides/config-plugins ```json { "expo": { - "plugins": ["react-native-health-connect"] + "plugins": ["expo-health-connect"] } } ``` diff --git a/docs/docs/permissions.md b/docs/docs/permissions.md index 50a3c16..3c6afd6 100644 --- a/docs/docs/permissions.md +++ b/docs/docs/permissions.md @@ -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. @@ -64,31 +64,33 @@ class PermissionsRationaleActivity: AppCompatActivity() { - - // highlight-start - - - - - ++ ++ ++ ++ - - - - - - - - // highlight-end ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ``` diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 50c19ed..d7d87ac 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -22,13 +22,8 @@ - - - - @@ -39,7 +34,7 @@ diff --git a/example/android/app/src/main/java/com/healthconnectexample/PermissionRationaleActivity.kt b/example/android/app/src/main/java/com/healthconnectexample/PermissionRationaleActivity.kt deleted file mode 100644 index 8acbf9d..0000000 --- a/example/android/app/src/main/java/com/healthconnectexample/PermissionRationaleActivity.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.healthconnectexample - -import android.os.Bundle -import android.webkit.WebResourceRequest -import android.webkit.WebView -import android.webkit.WebViewClient -import androidx.appcompat.app.AppCompatActivity - -class PermissionsRationaleActivity: AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - val webView = WebView(this) - webView.webViewClient = object : WebViewClient() { - override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean { - return false - } - } - - webView.loadUrl("https://developer.android.com/health-and-fitness/guides/health-connect/develop/get-started") - - setContentView(webView) - } -}