HealthPermission
public final class HealthPermission
A Permission either to read or write data associated with a Record type.
| See also | |
|---|---|
PermissionController |
Summary
Constants |
|
|---|---|
static final @NonNull String |
A permission to read exercise routes. |
static final @NonNull String |
A permission that allows to read the entire history of health data (of any type). |
static final @NonNull String |
A permission to read data in background. |
static final @NonNull String |
Allows an application to read the user's data about allergies and intolerances. |
static final @NonNull String |
Allows an application to read the user's data about medical conditions. |
static final @NonNull String |
Allows an application to read the user's laboratory result data. |
static final @NonNull String |
Allows an application to read the user's medication data. |
static final @NonNull String |
Allows an application to read the user's personal details. |
static final @NonNull String |
Allows an application to read the user's data about the practitioners who have interacted with them in their medical record. |
static final @NonNull String |
Allows an application to read the user's pregnancy data. |
static final @NonNull String |
Allows an application to read the user's data about medical procedures. |
static final @NonNull String |
Allows an application to read the user's social history data. |
static final @NonNull String |
Allows an application to read the user's data about immunizations and vaccinations. |
static final @NonNull 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. |
static final @NonNull String |
Allows an application to read the user's vital signs data. |
static final @NonNull String |
A permission to write exercise routes. |
static final @NonNull String |
Permission to write medical data records. |
Public methods |
|
|---|---|
static final @NonNull String |
<T extends Record> getReadPermission()Returns a permission defined in |
static final @NonNull String |
getReadPermission(@NonNull KClass<@NonNull Record> recordType)Returns a permission defined in |
static final @NonNull String |
<T extends Record> getWritePermission()Returns a permission defined in |
static final @NonNull String |
getWritePermission(@NonNull KClass<@NonNull Record> recordType)Returns a permission defined in |
Constants
PERMISSION_READ_EXERCISE_ROUTES
public static final @NonNull String PERMISSION_READ_EXERCISE_ROUTES
A permission to read exercise routes. The string value for this permission is android.permission.health.READ_EXERCISE_ROUTES.
This permission can't be granted via the standard permission request mechanism, and can only be granted by a user in Settings, or via the dialog launched by androidx.health.connect.client.contracts.ExerciseRouteRequestContract.
When this permission is granted, the app can read exercise routes without user interaction, however reading apps must be in the foreground unless android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND is also granted.
When this permission is revoked, exercise routes can only be obtained by launching the androidx.health.connect.client.contracts.ExerciseRouteRequestContract intent.
import androidx.health.connect.client.contracts.ExerciseRouteRequestContract import androidx.health.connect.client.readRecord import androidx.health.connect.client.records.ExerciseRoute import androidx.health.connect.client.records.ExerciseRouteResult import androidx.health.connect.client.records.ExerciseSessionRecord // See https://developer.android.com/training/basics/intents/result#launch for appropriately // handling ActivityResultContract. val requestExerciseRoute = activityResultCaller.registerForActivityResult(ExerciseRouteRequestContract()) { exerciseRoute: ExerciseRoute? -> if (exerciseRoute != null) { displayExerciseRoute(exerciseRoute) } else { // Consent was denied } } // Show exercise route, based on user action val exerciseSessionRecord = healthConnectClient.readRecord<ExerciseSessionRecord>(recordId).record when (val exerciseRouteResult = exerciseSessionRecord.exerciseRouteResult) { is ExerciseRouteResult.Data -> displayExerciseRoute(exerciseRouteResult.exerciseRoute) is ExerciseRouteResult.ConsentRequired -> requestExerciseRoute.launch(recordId) is ExerciseRouteResult.NoData -> Unit // No exercise route to show else -> Unit }
PERMISSION_READ_HEALTH_DATA_HISTORY
public static final @NonNull String PERMISSION_READ_HEALTH_DATA_HISTORY
A permission that allows to read the entire history of health data (of any type).
Without this permission:
-
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. -
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
public static final @NonNull String PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_ALLERGIES_INTOLERANCES
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_CONDITIONS
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_LABORATORY_RESULTS
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_MEDICATIONS
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_PERSONAL_DETAILS
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_PRACTITIONER_DETAILS
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_PREGNANCY
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_PROCEDURES
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_SOCIAL_HISTORY
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_VACCINES
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_VISITS
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
public static final @NonNull String PERMISSION_READ_MEDICAL_DATA_VITAL_SIGNS
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
public static final @NonNull String PERMISSION_WRITE_EXERCISE_ROUTE
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
public static final @NonNull String PERMISSION_WRITE_MEDICAL_DATA
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 methods
getReadPermission
public static final @NonNull String <T extends Record> getReadPermission()
Returns a permission defined in HealthPermission to read records of type T, such as StepsRecord.
| Returns | |
|---|---|
@NonNull String |
Permission to use with |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if the given record type is invalid. |
getReadPermission
public static final @NonNull String getReadPermission(@NonNull KClass<@NonNull Record> recordType)
Returns a permission defined in HealthPermission to read records of type recordType, such as StepsRecord::class.
| Returns | |
|---|---|
@NonNull String |
Permission to use with |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if the given record type is invalid. |
getWritePermission
public static final @NonNull String <T extends Record> getWritePermission()
Returns a permission defined in HealthPermission to write records of type T, such as StepsRecord:.
| Returns | |
|---|---|
@NonNull String |
Permission object to use with |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if the given record type is invalid. |
getWritePermission
public static final @NonNull String getWritePermission(@NonNull KClass<@NonNull Record> recordType)
Returns a permission defined in HealthPermission to write records of type recordType, such as StepsRecord::class.
| Returns | |
|---|---|
@NonNull String |
Permission object to use with |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if the given record type is invalid. |