Skip to main content

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.

  • Add the necessary permissions to AndroidManifest.xml:
android/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.health.READ_HEART_RATE"/>
+ <uses-permission android:name="android.permission.health.WRITE_HEART_RATE"/>
+ <uses-permission android:name="android.permission.health.READ_STEPS"/>
+ <uses-permission android:name="android.permission.health.WRITE_STEPS"/>
</manifest>
  • Create PermissionRationaleActivity.kt
android/app/src/main/java/com/healthconnectexample/PermissionRationaleActivity.kt
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)
}
}
  • Add the following highlighted code inside the application tag as well:
android/src/main/AndroidManifest.xml
    <activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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>

+ <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>

Setting up permissions in Expo

You will need to use EAS Build and Config plugins in your project.

  • Edit app.json and add the permissions you need.
{
"expo": {
...
"android": {
...
"permissions": [
"android.permission.health.READ_STEPS",
"android.permission.health.WRITE_STEPS",
"android.permission.health.READ_ACTIVE_CALORIES_BURNED"
]
},
...
}
}

Complete list of permissions

Record class typeRead permission declarationWrite permission declaration
ActiveCaloriesBurnedandroid.permission.health.READ_ACTIVE_CALORIES_BURNEDandroid.permission.health.WRITE_ACTIVE_CALORIES_BURNED
BasalBodyTemperatureandroid.permission.health.READ_BASAL_BODY_TEMPERATUREandroid.permission.health.WRITE_BASAL_BODY_TEMPERATURE
BasalMetabolicRateandroid.permission.health.READ_BASAL_METABOLIC_RATEandroid.permission.health.WRITE_BASAL_METABOLIC_RATE
BloodGlucoseandroid.permission.health.READ_BLOOD_GLUCOSEandroid.permission.health.WRITE_BLOOD_GLUCOSE
BloodPressureandroid.permission.health.READ_BLOOD_PRESSUREandroid.permission.health.WRITE_BLOOD_PRESSURE
BodyFatandroid.permission.health.READ_BODY_FATandroid.permission.health.WRITE_BODY_FAT
BodyTemperatureandroid.permission.health.READ_BODY_TEMPERATUREandroid.permission.health.WRITE_BODY_TEMPERATURE
BoneMassandroid.permission.health.READ_BONE_MASSandroid.permission.health.WRITE_BONE_MASS
CervicalMucusandroid.permission.health.READ_CERVICAL_MUCUSandroid.permission.health.WRITE_CERVICAL_MUCUS
CyclingPedalingCadenceandroid.permission.health.READ_EXERCISEandroid.permission.health.WRITE_EXERCISE
Distanceandroid.permission.health.READ_DISTANCEandroid.permission.health.WRITE_DISTANCE
ElevationGainedandroid.permission.health.READ_ELEVATION_GAINEDandroid.permission.health.WRITE_ELEVATION_GAINED
ExerciseSessionandroid.permission.health.READ_EXERCISEandroid.permission.health.WRITE_EXERCISE
FloorsClimbedandroid.permission.health.READ_FLOORS_CLIMBEDandroid.permission.health.WRITE_FLOORS_CLIMBED
HeartRateandroid.permission.health.READ_HEART_RATEandroid.permission.health.WRITE_HEART_RATE
Heightandroid.permission.health.READ_HEIGHTandroid.permission.health.WRITE_HEIGHT
Hydrationandroid.permission.health.READ_HYDRATIONandroid.permission.health.WRITE_HYDRATION
LeanBodyMassandroid.permission.health.READ_LEAN_BODY_MASSandroid.permission.health.WRITE_LEAN_BODY_MASS
MenstruationFlowandroid.permission.health.READ_MENSTRUATIONandroid.permission.health.WRITE_MENSTRUATION
MenstruationPeriodandroid.permission.health.READ_MENSTRUATIONandroid.permission.health.WRITE_MENSTRUATION
Nutritionandroid.permission.health.READ_NUTRITIONandroid.permission.health.WRITE_NUTRITION
OvulationTestandroid.permission.health.READ_OVULATION_TESTandroid.permission.health.WRITE_OVULATION_TEST
OxygenSaturationandroid.permission.health.READ_OXYGEN_SATURATIONandroid.permission.health.WRITE_OXYGEN_SATURATION
Powerandroid.permission.health.READ_POWERandroid.permission.health.WRITE_POWER
RespiratoryRateandroid.permission.health.READ_RESPIRATORY_RATEandroid.permission.health.WRITE_RESPIRATORY_RATE
RestingHeartRateandroid.permission.health.READ_RESTING_HEART_RATEandroid.permission.health.WRITE_RESTING_HEART_RATE
SexualActivityandroid.permission.health.READ_SEXUAL_ACTIVITYandroid.permission.health.WRITE_SEXUAL_ACTIVITY
SleepSessionandroid.permission.health.READ_SLEEPandroid.permission.health.WRITE_SLEEP
Speedandroid.permission.health.READ_SPEEDandroid.permission.health.WRITE_SPEED
StepsCadenceandroid.permission.health.READ_STEPSandroid.permission.health.WRITE_STEPS
Stepsandroid.permission.health.READ_STEPSandroid.permission.health.WRITE_STEPS
TotalCaloriesBurnedandroid.permission.health.READ_TOTAL_CALORIES_BURNEDandroid.permission.health.WRITE_TOTAL_CALORIES_BURNED
Vo2Maxandroid.permission.health.READ_VO2_MAXandroid.permission.health.WRITE_VO2_MAX
Weightandroid.permission.health.READ_WEIGHTandroid.permission.health.WRITE_WEIGHT
WheelchairPushesandroid.permission.health.READ_WHEELCHAIR_PUSHESandroid.permission.health.WRITE_WHEELCHAIR_PUSHES
WriteExerciseRouteandroid.permission.health.WRITE_EXERCISE_ROUTEN/A

You can read more about data types and permissions here.