class HealthPermission


A Permission either to read or write data associated with a Record type.

Summary

Constants

const String

A permission that allows to read the entire history of health data (of any type).

const String

A permission to read data in background.

const String

Allows an application to read the user's data about allergies and intolerances.

const String

Allows an application to read the user's data about medical conditions.

const String

Allows an application to read the user's laboratory result data.

const String

Allows an application to read the user's medication data.

const String

Allows an application to read the user's personal details.

const String

Allows an application to read the user's data about the practitioners who have interacted with them in their medical record.

const String

Allows an application to read the user's pregnancy data.

const String

Allows an application to read the user's data about medical procedures.

const String

Allows an application to read the user's social history data.

const String

Allows an application to read the user's data about immunizations and vaccinations.

const String

Allows an application to read the user's information about their encounters with health care practitioners, including things like location, time of appointment, and name of organization the visit was with.

const String

Allows an application to read the user's vital signs data.

const String

A permission to write exercise routes.

const String

Permission to write medical data records.

Public companion functions

inline String

Returns a permission defined in HealthPermission to read records of type T, such as StepsRecord.

String

Returns a permission defined in HealthPermission to read records of type recordType, such as StepsRecord::class.

inline String

Returns a permission defined in HealthPermission to write records of type T, such as StepsRecord:.

String

Returns a permission defined in HealthPermission to write records of type recordType, such as StepsRecord::class.

Constants

PERMISSION_READ_HEALTH_DATA_HISTORY

const val PERMISSION_READ_HEALTH_DATA_HISTORYString

A permission that allows to read the entire history of health data (of any type).

Without this permission:

  1. Any attempt to read a single data point, via HealthConnectClient.readRecord, older than 30 days from before the first HealthConnect permission was granted to the calling app, will result in an error.

  2. Any other read attempts will not return data points older than 30 days from before the first HealthConnect permission was granted to the calling app.

This permission applies for the following api methods: HealthConnectClient.readRecord, HealthConnectClient.readRecords, HealthConnectClient.aggregate, HealthConnectClient.aggregateGroupByPeriod, HealthConnectClient.aggregateGroupByDuration and HealthConnectClient.getChanges.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_READ_HEALTH_DATA_HISTORY as an argument.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_HEALTH_DATA_HISTORY

val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (PERMISSION_READ_HEALTH_DATA_HISTORY in grantedPermissions) {
            // It will be possible to read data older than 30 days from now on
        } else {
            // Permission denied, it won't be possible to read data older than 30 days
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_READ_HEALTH_DATA_HISTORY) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request history read permissions
    requestPermission.launch(setOf(PERMISSION_READ_HEALTH_DATA_HISTORY))
}

PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND

const val PERMISSION_READ_HEALTH_DATA_IN_BACKGROUNDString

A permission to read data in background.

An attempt to read data in background without this permission may result in an error.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_READ_HEALTH_DATA_IN_BACKGROUND as an argument.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND

val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND in grantedPermissions) {
            // It will be possible to read data in background from now on
        } else {
            // Permission denied, it won't be possible to read data in background
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_READ_HEALTH_DATA_IN_BACKGROUND) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request background reads permission
    requestPermission.launch(setOf(PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND))
}
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND
import androidx.health.connect.client.readRecord
import androidx.health.connect.client.records.StepsRecord
import androidx.health.connect.client.request.ReadRecordsRequest
import androidx.health.connect.client.time.TimeRangeFilter

val grantedPermissions = healthConnectClient.permissionController.getGrantedPermissions()

// The permission should be requested and granted beforehand when the app is in foreground
if (PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND !in grantedPermissions) {
    return
}

val response =
    healthConnectClient.readRecords(
        ReadRecordsRequest<StepsRecord>(
            timeRangeFilter = TimeRangeFilter.between(startTime, endTime),
        )
    )

for (stepsRecord in response.records) {
    // Process each record
}

PERMISSION_READ_MEDICAL_DATA_ALLERGIES_INTOLERANCES

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_ALLERGIES_INTOLERANCESString

Allows an application to read the user's data about allergies and intolerances.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_READ_MEDICAL_DATA_CONDITIONS

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_CONDITIONSString

Allows an application to read the user's data about medical conditions.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_READ_MEDICAL_DATA_LABORATORY_RESULTS

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_LABORATORY_RESULTSString

Allows an application to read the user's laboratory result data.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_READ_MEDICAL_DATA_MEDICATIONS

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_MEDICATIONSString

Allows an application to read the user's medication data.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_READ_MEDICAL_DATA_PERSONAL_DETAILS

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_PERSONAL_DETAILSString

Allows an application to read the user's personal details.

This is demographic information such as name, date of birth, contact details like address or telephone number and so on. For more examples see the FHIR Patient resource at https://www.hl7.org/fhir/patient.html.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_READ_MEDICAL_DATA_PRACTITIONER_DETAILS

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_PRACTITIONER_DETAILSString

Allows an application to read the user's data about the practitioners who have interacted with them in their medical record. This is the information about the clinicians (doctors, nurses, etc) but also other practitioners (masseurs, physiotherapists, etc) who have been involved with the patient.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_READ_MEDICAL_DATA_PREGNANCY

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_PREGNANCYString

Allows an application to read the user's pregnancy data.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_READ_MEDICAL_DATA_PROCEDURES

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_PROCEDURESString

Allows an application to read the user's data about medical procedures.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_READ_MEDICAL_DATA_SOCIAL_HISTORY

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_SOCIAL_HISTORYString

Allows an application to read the user's social history data.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_READ_MEDICAL_DATA_VACCINES

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_VACCINESString

Allows an application to read the user's data about immunizations and vaccinations.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_READ_MEDICAL_DATA_VISITS

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_VISITSString

Allows an application to read the user's information about their encounters with health care practitioners, including things like location, time of appointment, and name of organization the visit was with. Despite the name visit it covers remote encounters such as telephone or videoconference appointments.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_READ_MEDICAL_DATA_VITAL_SIGNS

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_READ_MEDICAL_DATA_VITAL_SIGNSString

Allows an application to read the user's vital signs data.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

PERMISSION_WRITE_EXERCISE_ROUTE

const val PERMISSION_WRITE_EXERCISE_ROUTEString

A permission to write exercise routes.

This permission must be granted to successfully insert a route as a field of the corresponding androidx.health.connect.client.records.ExerciseSessionRecord. An attempt to insert/update a session with a set route without the permission granted will result in a failed call and the session insertion/update will be rejected.

If the permission is not granted the previously written route will not be deleted if the session gets updated with no route set.

import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_EXERCISE_ROUTE
import androidx.health.connect.client.permission.HealthPermission.Companion.getWritePermission
import androidx.health.connect.client.records.ExerciseRoute
import androidx.health.connect.client.records.ExerciseSessionRecord
import androidx.health.connect.client.records.metadata.Metadata
import androidx.health.connect.client.units.Length

val grantedPermissions = healthConnectClient.permissionController.getGrantedPermissions()

if (!grantedPermissions.contains(getWritePermission(ExerciseSessionRecord::class))) {
    return
}

val sessionStartTime = Instant.parse("2023-07-11T10:00:00.00Z")
val sessionDuration = Duration.ofMinutes(10)

val startLatitude = 51.511831
val endLatitude = 51.506007
val startLongitude = -0.165785
val endLongitude = -0.164888
val latitudeDeltaPerSecond = (endLatitude - startLatitude) / sessionDuration.seconds
val longitudeDeltaPerSecond = (endLongitude - startLongitude) / sessionDuration.seconds

val exerciseRoute =
    if (grantedPermissions.contains(PERMISSION_WRITE_EXERCISE_ROUTE)) {
        ExerciseRoute(
            List(sessionDuration.seconds.toInt()) { timeSeconds ->
                ExerciseRoute.Location(
                    time = sessionStartTime.plusSeconds(timeSeconds.toLong()),
                    latitude = startLatitude + latitudeDeltaPerSecond * timeSeconds,
                    longitude = startLongitude + longitudeDeltaPerSecond * timeSeconds,
                    horizontalAccuracy = Length.meters(2.0),
                    verticalAccuracy = Length.meters(2.0),
                    altitude = Length.meters(19.0)
                )
            }
        )
    } else {
        null
    }

val exerciseSessionRecord =
    ExerciseSessionRecord(
        startTime = sessionStartTime,
        startZoneOffset = ZoneOffset.UTC,
        endTime = sessionStartTime.plus(sessionDuration),
        endZoneOffset = ZoneOffset.UTC,
        metadata = Metadata.manualEntry(),
        exerciseType = ExerciseSessionRecord.EXERCISE_TYPE_RUNNING,
        title = "Morning Run",
        notes = "A nice run in a park",
        exerciseRoute = exerciseRoute
    )

healthConnectClient.insertRecords(listOf(exerciseSessionRecord))

PERMISSION_WRITE_MEDICAL_DATA

@ExperimentalPersonalHealthRecordApi
const val PERMISSION_WRITE_MEDICAL_DATAString

Permission to write medical data records. This permission allows for the write of medical data of any type. Note that read permissions are specified per-type.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call HealthConnectFeatures.getFeatureStatus and pass HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD as an argument. If not available, this permission will not be granted if requested.

import androidx.health.connect.client.HealthConnectFeatures
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_READ_MEDICAL_DATA_VACCINES
import androidx.health.connect.client.permission.HealthPermission.Companion.PERMISSION_WRITE_MEDICAL_DATA

// The set of medical permissions to be requested (add additional read permissions as required)
val medicalPermissions =
    setOf(PERMISSION_WRITE_MEDICAL_DATA, PERMISSION_READ_MEDICAL_DATA_VACCINES)
val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (grantedPermissions.containsAll(medicalPermissions)) {
            // Permissions granted to write health data and read immunizations
        } else {
            // User denied permission to write health data and/or read immunizations
        }
    }

if (
    features.getFeatureStatus(HealthConnectFeatures.FEATURE_PERSONAL_HEALTH_RECORD) ==
        HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {
    // The feature is available, request medical permissions
    requestPermission.launch(medicalPermissions)
}

Public companion functions

getReadPermission

inline fun <T : Record> getReadPermission(): String

Returns a permission defined in HealthPermission to read records of type T, such as StepsRecord.

Throws
kotlin.IllegalArgumentException

if the given record type is invalid.

getReadPermission

Added in 1.1.0-beta02
fun getReadPermission(recordType: KClass<Record>): String

Returns a permission defined in HealthPermission to read records of type recordType, such as StepsRecord::class.

Throws
kotlin.IllegalArgumentException

if the given record type is invalid.

getWritePermission

inline fun <T : Record> getWritePermission(): String

Returns a permission defined in HealthPermission to write records of type T, such as StepsRecord:.

Returns
String

Permission object to use with androidx.health.connect.client.PermissionController.

Throws
kotlin.IllegalArgumentException

if the given record type is invalid.

getWritePermission

Added in 1.1.0-beta02
fun getWritePermission(recordType: KClass<Record>): String

Returns a permission defined in HealthPermission to write records of type recordType, such as StepsRecord::class.

Returns
String

Permission object to use with androidx.health.connect.client.PermissionController.

Throws
kotlin.IllegalArgumentException

if the given record type is invalid.