# HealthConnectClient

Artifact: [androidx.health.connect:connect-client](https://developer.android.com/jetpack/androidx/releases/health-connect) [View Source](https://cs.android.com/search?q=file:androidx/health/connect/client/HealthConnectClient.kt+class:androidx.health.connect.client.HealthConnectClient) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

*** ** * ** ***


```
interface HealthConnectClient
```

<br />

Known direct subclasses [FakeHealthConnectClient](https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient` | Fake `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient` to be used in tests for components that use it as a dependency. |

*** ** * ** ***

Interface to access health and fitness records.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#SDK_AVAILABLE() = 3` The Health Connect SDK APIs are available. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#SDK_UNAVAILABLE() = 1` The Health Connect SDK is unavailable on this device at the time. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED() = 2` The Health Connect SDK APIs are currently unavailable, the provider is either not installed or needs to be updated. |

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getHealthConnectManageDataIntent(android.content.Context,kotlin.String)( context: https://developer.android.com/reference/android/content/Context.html, providerPackageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html )` Intent to open Health Connect data management screen on this phone. |
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getOrCreate(android.content.Context,kotlin.String)(context: https://developer.android.com/reference/android/content/Context.html, providerPackageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Retrieves an IPC-backed `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient` instance binding to an available implementation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getSdkStatus(android.content.Context,kotlin.String)(context: https://developer.android.com/reference/android/content/Context.html, providerPackageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Determines whether the Health Connect SDK is available on this device at the moment. |

| ### Public companion properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#ACTION_HEALTH_CONNECT_SETTINGS()` Intent action to open Health Connect settings on this phone. |

| ### Public functions |
|---|---|
| `suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#aggregate(androidx.health.connect.client.request.AggregateRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateRequest)` Reads `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric`s according to requested read criteria: `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record`s from `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateRequest#dataOriginFilter()` and within `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateRequest#timeRangeFilter()`. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByDuration>` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#aggregateGroupByDuration(androidx.health.connect.client.request.AggregateGroupByDurationRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByDurationRequest)` Reads `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric`s according to requested read criteria specified in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByDurationRequest`. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByPeriod>` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#aggregateGroupByPeriod(androidx.health.connect.client.request.AggregateGroupByPeriodRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByPeriodRequest)` Reads `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric`s according to requested read criteria specified in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByPeriodRequest`. |
| `open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingResponse` | `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/ExperimentalMatchmakingApi https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#checkIfMatchmakingIsPossible(androidx.health.connect.client.matchmaking.MatchmakingRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest)` Checks if launching the intent returned by `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#createMatchmakingIntent(androidx.health.connect.client.matchmaking.MatchmakingRequest)` with the same arguments will result in showing at least one matching application or device. |
| `open https://developer.android.com/reference/android/content/Intent.html` | `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/ExperimentalMatchmakingApi https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#createMatchmakingIntent(androidx.health.connect.client.matchmaking.MatchmakingRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest)` Creates an `https://developer.android.com/reference/android/content/Intent.html` to launch a Health Connect flow where users can: |
| `open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` | `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi @https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA") https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#createMedicalDataSource(androidx.health.connect.client.request.CreateMedicalDataSourceRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/CreateMedicalDataSourceRequest)` Creates a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` using a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/CreateMedicalDataSourceRequest`. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi @https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA") https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteMedicalDataSourceWithData(kotlin.String)(id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Deletes a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` and all data contained within it. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA") @https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteMedicalResources(kotlin.collections.List)(ids: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId>)` Deletes a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s by the provided list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId`s. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA") @https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteMedicalResources(androidx.health.connect.client.request.DeleteMedicalResourcesRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/DeleteMedicalResourcesRequest)` Deletes `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s based on given filters in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/DeleteMedicalResourcesRequest`. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,androidx.health.connect.client.time.TimeRangeFilter)( recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>, timeRangeFilter: https://developer.android.com/reference/kotlin/androidx/health/connect/client/time/TimeRangeFilter )` Deletes any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` of the given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,androidx.health.connect.client.time.TimeRangeFilter)` in the given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,androidx.health.connect.client.time.TimeRangeFilter)` (automatically filtered to `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` belonging to the calling application). |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,kotlin.collections.List,kotlin.collections.List)( recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>, recordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, clientRecordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html> )` Deletes one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` by their identifiers. |
| `suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)(changesToken: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Retrieves changes in Health Connect, from a specific point in time represented by provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)`. |
| `suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)(changesToken: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, pageSize: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 5000) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Same as `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)` method but also allows specifying a preferred `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)`. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChangesToken(androidx.health.connect.client.request.ChangesTokenRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ChangesTokenRequest)` Retrieves a changes-token, representing a point in time in the underlying Android Health Platform for a given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ChangesTokenRequest`. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource>` | `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getMedicalDataSources(kotlin.collections.List)(ids: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>)` Gets `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s for the provided list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource#id()`. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource>` | `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getMedicalDataSources(androidx.health.connect.client.request.GetMedicalDataSourcesRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/GetMedicalDataSourcesRequest)` Gets the requested `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s using `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/GetMedicalDataSourcesRequest`. |
| `suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/InsertRecordsResponse` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#insertRecords(kotlin.collections.List)(records: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>)` Inserts one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` and returns newly assigned `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#id()` generated. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource>` | `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readMedicalResources(kotlin.collections.List)(ids: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId>)` Reads a collection of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s given a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId`s. |
| `open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadMedicalResourcesResponse` | `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readMedicalResources(androidx.health.connect.client.request.ReadMedicalResourcesRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadMedicalResourcesRequest)` Reads `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s by request, either `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadMedicalResourcesInitialRequest` or `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadMedicalResourcesPageRequest`. |
| `suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadRecordResponse<T>` | `<T : https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record> https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readRecord(kotlin.reflect.KClass,kotlin.String)(recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<T>, recordId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Reads one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` point with its `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readRecord(kotlin.reflect.KClass,kotlin.String)` and `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readRecord(kotlin.reflect.KClass,kotlin.String)`. |
| `suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadRecordsResponse<T>` | `<T : https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record> https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readRecords(androidx.health.connect.client.request.ReadRecordsRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadRecordsRequest<T>)` Retrieves a collection of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record`s. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#updateRecords(kotlin.collections.List)(records: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>)` Updates one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` of given UIDs to newly specified values. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA") @https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#upsertMedicalResources(kotlin.collections.List)(requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest>)` Inserts or updates a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s using `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest`s. |

| ### Public properties |
|---|---|
| `open https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#features()` Access operations related to feature availability. |
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/PermissionController` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#permissionController()` Access operations related to permissions. |

| ### Extension functions |
|---|---|
| `suspend inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `<T : https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record> https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient.https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#(androidx.health.connect.client.HealthConnectClient).deleteRecords(androidx.health.connect.client.time.TimeRangeFilter)( timeRangeFilter: https://developer.android.com/reference/kotlin/androidx/health/connect/client/time/TimeRangeFilter )` Deletes any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` of type `https://developer.android.com/reference/kotlin/androidx/health/connect/client/package-summary#(androidx.health.connect.client.HealthConnectClient).deleteRecords(androidx.health.connect.client.time.TimeRangeFilter)` in the given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/package-summary#(androidx.health.connect.client.HealthConnectClient).deleteRecords(androidx.health.connect.client.time.TimeRangeFilter)` (automatically filtered to `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` belonging to the calling application). |
| `suspend inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `<T : https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record> https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient.https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#(androidx.health.connect.client.HealthConnectClient).deleteRecords(kotlin.collections.List,kotlin.collections.List)( recordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, clientRecordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html> )` Deletes one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` by their identifiers. |
| `suspend inline https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadRecordResponse<T>` | `<T : https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record> https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient.https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#(androidx.health.connect.client.HealthConnectClient).readRecord(kotlin.String)(recordId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Reads one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` point of type `https://developer.android.com/reference/kotlin/androidx/health/connect/client/package-summary#(androidx.health.connect.client.HealthConnectClient).readRecord(kotlin.String)` and with the specified `https://developer.android.com/reference/kotlin/androidx/health/connect/client/package-summary#(androidx.health.connect.client.HealthConnectClient).readRecord(kotlin.String)`. |

## Constants

### SDK_AVAILABLE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
const val SDK_AVAILABLE = 3: Int
```

The Health Connect SDK APIs are available.

Apps can subsequently call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getOrCreate(android.content.Context,kotlin.String)` to get an instance of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient`.

### SDK_UNAVAILABLE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
const val SDK_UNAVAILABLE = 1: Int
```

The Health Connect SDK is unavailable on this device at the time. This can be due to the device running a lower than required Android Version.

Apps should hide any integration points to Health Connect in this case.

### SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
const val SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED = 2: Int
```

The Health Connect SDK APIs are currently unavailable, the provider is either not installed or needs to be updated.

Apps may choose to redirect to package installers to find a suitable APK.

## Public companion functions

### getHealthConnectManageDataIntent

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
fun getHealthConnectManageDataIntent(
    context: Context,
    providerPackageName: String = DEFAULT_PROVIDER_PACKAGE_NAME
): Intent
```

Intent to open Health Connect data management screen on this phone. Developers should use this if they want to re-direct the user to Health Connect data management.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the context |
| `providerPackageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html = DEFAULT_PROVIDER_PACKAGE_NAME` | optional alternative package provider to choose for backend implementation |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html` | Intent to open Health Connect data management screen. |

### getOrCreate

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
fun getOrCreate(
    context: Context,
    providerPackageName: String = DEFAULT_PROVIDER_PACKAGE_NAME
): HealthConnectClient
```

Retrieves an IPC-backed `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient` instance binding to an available implementation.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the context |
| `providerPackageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html = DEFAULT_PROVIDER_PACKAGE_NAME` | optional alternative package provider to choose for backend implementation |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient` | instance of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient` ready for issuing requests |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | if service not available due to SDK version too low or running in a profile |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the SDK is not available |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getSdkStatus(android.content.Context,kotlin.String)` |   |

### getSdkStatus

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
fun getSdkStatus(
    context: Context,
    providerPackageName: String = DEFAULT_PROVIDER_PACKAGE_NAME
): Int
```

Determines whether the Health Connect SDK is available on this device at the moment.

```kotlin
import androidx.health.connect.client.HealthConnectClient

val availabilityStatus = HealthConnectClient.getSdkStatus(context, providerPackageName)
if (availabilityStatus == HealthConnectClient.SDK_UNAVAILABLE) {
    return // early return as there is no viable integration
}
if (availabilityStatus == HealthConnectClient.SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED) {
    // Optionally redirect to package installer to find a provider, for example:
    val uriString =
        "market://details?id=$providerPackageName&url=healthconnect%3A%2F%2Fonboarding"
    context.startActivity(
        Intent(Intent.ACTION_VIEW).apply {
            setPackage("com.android.vending")
            data = Uri.parse(uriString)
            putExtra("overlay", true)
            putExtra("callerId", context.packageName)
        }
    )
    return
}
val healthConnectClient = HealthConnectClient.getOrCreate(context)
// Issue operations with healthConnectClient
```

Value is one of the following:

- `1`
- `2`
- `3`

<br />

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the context |
| `providerPackageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html = DEFAULT_PROVIDER_PACKAGE_NAME` | optional package provider to choose for backend implementation |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | One of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#SDK_UNAVAILABLE()`, `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED()`, or `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#SDK_AVAILABLE()` |

## Public companion properties

### ACTION_HEALTH_CONNECT_SETTINGS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
val ACTION_HEALTH_CONNECT_SETTINGS: String
```

Intent action to open Health Connect settings on this phone. Developers should use this if they want to re-direct the user to Health Connect.

## Public functions

### aggregate

```
suspend fun aggregate(request: AggregateRequest): AggregationResult
```

Reads `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric`s according to requested read criteria: `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record`s from `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateRequest#dataOriginFilter()` and within `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateRequest#timeRangeFilter()`.

```kotlin
import androidx.health.connect.client.records.DistanceRecord
import androidx.health.connect.client.request.AggregateRequest
import androidx.health.connect.client.time.TimeRangeFilter

val response =
    healthConnectClient.aggregate(
        AggregateRequest(
            metrics = setOf(DistanceRecord.DISTANCE_TOTAL),
            timeRangeFilter = TimeRangeFilter.between(startTime, endTime),
        )
    )
// The result may be null if no data is available in the time range.
val distanceTotalInMeters = response[DistanceRecord.DISTANCE_TOTAL]?.inMeters
```

Example code to retrieve statistical aggregates like maximum or minimum heart rate:

```kotlin
import androidx.health.connect.client.records.HeartRateRecord
import androidx.health.connect.client.request.AggregateRequest
import androidx.health.connect.client.time.TimeRangeFilter

val response =
    healthConnectClient.aggregate(
        AggregateRequest(
            setOf(HeartRateRecord.BPM_MAX, HeartRateRecord.BPM_MIN),
            timeRangeFilter = TimeRangeFilter.between(startTime, endTime),
        )
    )
// The result may be null if no data is available in the time range.
val minimumHeartRate = response[HeartRateRecord.BPM_MIN]
val maximumHeartRate = response[HeartRateRecord.BPM_MAX]
```

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateRequest` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateRequest` object specifying `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric`s to aggregate and other filters. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult` | the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult` that contains aggregated values. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. Example code to aggregate cumulative data like distance: |

### aggregateGroupByDuration

```
suspend fun aggregateGroupByDuration(request: AggregateGroupByDurationRequest): List<AggregationResultGroupedByDuration>
```

Reads `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric`s according to requested read criteria specified in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByDurationRequest`.

This method is similar to `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#aggregate(androidx.health.connect.client.request.AggregateRequest)` but instead of returning one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult` for the entire query's time interval, it returns a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByDuration`, with each row keyed by start and end time. For example: steps for today bucketed by hours.

An `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByDuration` is returned only if there are `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to aggregate within start and end time of the row.

```kotlin
import androidx.health.connect.client.records.StepsRecord
import androidx.health.connect.client.request.AggregateGroupByDurationRequest
import androidx.health.connect.client.time.TimeRangeFilter

val response =
    healthConnectClient.aggregateGroupByDuration(
        AggregateGroupByDurationRequest(
            metrics = setOf(StepsRecord.COUNT_TOTAL),
            timeRangeFilter = TimeRangeFilter.between(startTime, endTime),
            timeRangeSlicer = Duration.ofMinutes(1),
        )
    )
for (monthlyResult in response) {
    // The result may be null if no data is available in the time range.
    val totalSteps = monthlyResult.result[StepsRecord.COUNT_TOTAL]
}
```

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByDurationRequest` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByDurationRequest` object specifying `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric`s to aggregate and other filters. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByDuration>` | a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByDuration`s, each contains aggregated values and start/end time of the row. The list is sorted by time in ascending order. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. Example code to retrieve cumulative step count for each minute within provided time range: |

### aggregateGroupByPeriod

```
suspend fun aggregateGroupByPeriod(request: AggregateGroupByPeriodRequest): List<AggregationResultGroupedByPeriod>
```

Reads `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric`s according to requested read criteria specified in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByPeriodRequest`.

This method is similar to `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#aggregate(androidx.health.connect.client.request.AggregateRequest)` but instead of returning one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult` for the entire query's time interval, it returns a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByPeriod`, with each row keyed by start and end time. For example: steps for this month bucketed by day.

An `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByPeriod` is returned only if there are `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to aggregate within start and end time of the row.

```kotlin
import androidx.health.connect.client.records.StepsRecord
import androidx.health.connect.client.request.AggregateGroupByPeriodRequest
import androidx.health.connect.client.time.TimeRangeFilter

val response =
    healthConnectClient.aggregateGroupByPeriod(
        AggregateGroupByPeriodRequest(
            metrics = setOf(StepsRecord.COUNT_TOTAL),
            timeRangeFilter = TimeRangeFilter.between(startTime, endTime),
            timeRangeSlicer = Period.ofMonths(1),
        )
    )
for (monthlyResult in response) {
    // The result may be null if no data is available in the time range.
    val totalSteps = monthlyResult.result[StepsRecord.COUNT_TOTAL]
}
```

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByPeriodRequest` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByPeriodRequest` object specifying `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric`s to aggregate and other filters. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByPeriod>` | a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByPeriod`s, each contains aggregated values and start/end time of the row. The list is sorted by time in ascending order. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. Example code to retrieve cumulative step count for each month within provided time range: |

### checkIfMatchmakingIsPossible

```
@ExperimentalMatchmakingApi
open suspend fun checkIfMatchmakingIsPossible(request: MatchmakingRequest): MatchmakingResponse
```

Checks if launching the intent returned by `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#createMatchmakingIntent(androidx.health.connect.client.matchmaking.MatchmakingRequest)` with the same arguments will result in showing at least one matching application or device.

- Returns `true` if the flow launched by `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#createMatchmakingIntent(androidx.health.connect.client.matchmaking.MatchmakingRequest)` would display at least one matching data source, allowing the user to take action.

- Returns `false` if the launched flow would immediately return `https://developer.android.com/reference/android/app/Activity.html#RESULT_CANCELED` because there are no relevant data sources to show.

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingResponse` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingResponse`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | if the feature is not available. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#createMatchmakingIntent(androidx.health.connect.client.matchmaking.MatchmakingRequest)` | This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#getFeatureStatus(kotlin.Int)` and pass `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#FEATURE_MATCHMAKING()` as an argument. An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` would be thrown if the feature is not available. |

### createMatchmakingIntent

Added in [1.2.0-alpha06](https://developer.android.com/jetpack/androidx/releases/health-connect#1.2.0-alpha06)

```
@ExperimentalMatchmakingApi
open fun createMatchmakingIntent(request: MatchmakingRequest): Intent
```

Creates an `https://developer.android.com/reference/android/content/Intent.html` to launch a Health Connect flow where users can:

- **Discover compatible data sources:** See other installed data sources that have not yet granted permissions to write some of the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` classes the calling app can read.

- **Grant missing permissions:** Easily grant these discovered data sources the necessary write permissions for health data record types that haven't been granted yet. Only record types the calling package is permitted to read are being considered.

This flow helps users connect new data sources to Health Connect, by matching record types readable by the calling package to appropriate writing data sources.

This intent must be launched using `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher` rather than `https://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent)`. The launched activity may return a result code indicating the user's interaction with the flow:

- `https://developer.android.com/reference/android/app/Activity.html#RESULT_OK`: The user has successfully granted permissions to at least one application or device.

- `https://developer.android.com/reference/android/app/Activity.html#RESULT_CANCELED`: The user has canceled the flow, either by closing the activity or by not granting any permissions. `https://developer.android.com/reference/android/app/Activity.html#RESULT_CANCELED` can also occur if the intent was launched when no matching apps are available. This can be avoided by ensuring `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#checkIfMatchmakingIsPossible(androidx.health.connect.client.matchmaking.MatchmakingRequest)` returns `true` before launching the intent.

The launched flow will only show packages that have declared, but not yet been granted write permissions (that have not been denied by the user twice) for at least one of the relevant record types, and for the relevant included/excluded data sources:

- **If `https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest#recordTypes()` is not empty:** The launched screen will focus on data sources capable of writing data for at least one of the specified health record types. The user can then grant write permissions to these discovered data sources specifically for these types. Record types the calling app does not have permission to read are ignored.

- **If `https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest#recordTypes()` is empty:** The system first determines all health data record types for which the calling package has already been granted read permission. The launched flow will then display data sources capable of writing any of these record types, where the user can grant write permissions for these types.

- **If `https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest#includedDataSources()` is not empty:** Only data sources whose package names are present in this set are considered for matchmaking.

- **If `https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest#excludedDataSources()` is not empty:** Data sources whose package names are present in this set are excluded from matchmaking.

- **If both are empty:** All compatible data sources are considered.

Note: If a data source is an app, the calling app must have visibility of the package name (e.g. declared in the manifest inside `<queries>`). If a data source is a device, the calling app does not need to declare it in the manifest.

`https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest#includedDataSources()` and `https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest#excludedDataSources()` cannot both be set at the same time.

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html` | `https://developer.android.com/reference/android/content/Intent.html` configured to show the matchmaking flow. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | if the feature is not available. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#checkIfMatchmakingIsPossible(androidx.health.connect.client.matchmaking.MatchmakingRequest)` | This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#getFeatureStatus(kotlin.Int)` and pass `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#FEATURE_MATCHMAKING()` as an argument. |

### createMedicalDataSource

```
@ExperimentalPersonalHealthRecordApi
@RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA")
open suspend fun createMedicalDataSource(request: CreateMedicalDataSourceRequest): MedicalDataSource
```

Creates a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` using a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/CreateMedicalDataSourceRequest`.

Regarding permissions:

- Caller must hold `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` in order to call this API, otherwise a `https://developer.android.com/reference/java/lang/SecurityException.html` will be thrown.

- With `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` granted, caller is permitted to call this API in either foreground or background.

Medical data is represented using the [Fast Healthcare Interoperability Resources (FHIR)](https://hl7.org/fhir/) standard.

A `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` needs to be created before any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s for that source can be inserted. Separate `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s should be created for medical records coming from different sources (e.g. different FHIR endpoints, different healthcare systems), unless the data has been reconciled and all records have a unique combination of resource type and resource id.

The `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/CreateMedicalDataSourceRequest#displayName()` must be unique across all medical data sources created by an app, otherwise an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` will be thrown. See `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/CreateMedicalDataSourceRequest#fhirBaseUri()` for more details on the FHIR base URI. The data source can not be updated after creation.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#getFeatureStatus(kotlin.Int)` and pass `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#FEATURE_PERSONAL_HEALTH_RECORD()` as an argument. An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` would be thrown if the feature is not available.

```kotlin
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_PERSONAL_HEALTH_RECORD
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_STATUS_AVAILABLE
import androidx.health.connect.client.records.FhirVersion
import androidx.health.connect.client.records.MedicalDataSource
import androidx.health.connect.client.request.CreateMedicalDataSourceRequest

// Ensure `FEATURE_PERSONAL_HEALTH_RECORD` is available before calling PHR apis
if (
    healthConnectClient.features.getFeatureStatus(FEATURE_PERSONAL_HEALTH_RECORD) !=
        FEATURE_STATUS_AVAILABLE
) {
    return
}

// Create a `MedicalDataSource`
// Note that `displayName` must be unique across `MedicalDataSource`s
val medicalDataSource: MedicalDataSource =
    healthConnectClient.createMedicalDataSource(
        CreateMedicalDataSourceRequest(
            fhirBaseUri = Uri.parse("https://fhir.com/oauth/api/FHIR/R4/"),
            displayName = "Test Data Source",
            fhirVersion = FhirVersion(4, 0, 1),
        )
    )
```

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/CreateMedicalDataSourceRequest` | request containing details of the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` to be created |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` | the created `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException.html` | if caller does not hold `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()`. |

### deleteMedicalDataSourceWithData

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
@ExperimentalPersonalHealthRecordApi
@RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA")
open suspend fun deleteMedicalDataSourceWithData(id: String): Unit
```

Deletes a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` and all data contained within it.

Regarding permissions:

- Caller must hold `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` in order to call this API, otherwise a `https://developer.android.com/reference/java/lang/SecurityException.html` will be thrown.

- With `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` granted, caller is permitted to call this API in either foreground or background.

- Caller may only delete data sources it created.

Medical data is represented using the [Fast Healthcare Interoperability Resources (FHIR)](https://hl7.org/fhir/) standard.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#getFeatureStatus(kotlin.Int)` and pass `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#FEATURE_PERSONAL_HEALTH_RECORD()` as an argument. An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` would be thrown if the feature is not available.

```kotlin
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_PERSONAL_HEALTH_RECORD
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_STATUS_AVAILABLE
import androidx.health.connect.client.records.FhirVersion
import androidx.health.connect.client.records.MedicalDataSource
import androidx.health.connect.client.request.CreateMedicalDataSourceRequest

// Ensure `FEATURE_PERSONAL_HEALTH_RECORD` is available before calling PHR apis
if (
    healthConnectClient.features.getFeatureStatus(FEATURE_PERSONAL_HEALTH_RECORD) !=
        FEATURE_STATUS_AVAILABLE
) {
    return
}

// Get or creates a `MedicalDataSource`
// Each `MedicalDataSource` is assigned an `id` by the system on creation
val medicalDataSource: MedicalDataSource =
    healthConnectClient.createMedicalDataSource(
        CreateMedicalDataSourceRequest(
            fhirBaseUri = Uri.parse("https://fhir.com/oauth/api/FHIR/R4/"),
            displayName = "Test Data Source",
            fhirVersion = FhirVersion(4, 0, 1),
        )
    )

// Delete the `MedicalDataSource` that has the specified `id`
healthConnectClient.deleteMedicalDataSourceWithData(medicalDataSource.id)
```

| Parameters |
|---|---|
| `id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The id of the data source to delete. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteMedicalDataSourceWithData(kotlin.String)` is invalid, does not exist, or owned by another app. |

### deleteMedicalResources

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
@RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA")
@ExperimentalPersonalHealthRecordApi
open suspend fun deleteMedicalResources(ids: List<MedicalResourceId>): Unit
```

Deletes a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s by the provided list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId`s.

- If any ID in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteMedicalResources(kotlin.collections.List)` is invalid, the API will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`, and nothing will be deleted.

- If any ID in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteMedicalResources(kotlin.collections.List)` does not exist, that ID will be ignored, while deletion on other IDs will be performed.

Regarding permissions:

- Caller must hold `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` in order to call this API, even then, it can only delete its own data. If any of the items in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteMedicalResources(kotlin.collections.List)` belongs to another app, they will be ignored.

- Deletes are permitted in the foreground or background.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#getFeatureStatus(kotlin.Int)` and pass `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#FEATURE_PERSONAL_HEALTH_RECORD()` as an argument. An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` would be thrown if the feature is not available.

```kotlin
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_PERSONAL_HEALTH_RECORD
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_STATUS_AVAILABLE
import androidx.health.connect.client.records.FhirVersion
import androidx.health.connect.client.records.MedicalDataSource
import androidx.health.connect.client.records.MedicalResource
import androidx.health.connect.client.records.MedicalResourceId
import androidx.health.connect.client.request.CreateMedicalDataSourceRequest
import androidx.health.connect.client.request.UpsertMedicalResourceRequest

// Ensure `FEATURE_PERSONAL_HEALTH_RECORD` is available before calling PHR apis
if (
    healthConnectClient.features.getFeatureStatus(FEATURE_PERSONAL_HEALTH_RECORD) !=
        FEATURE_STATUS_AVAILABLE
) {
    return
}

// Get or create a `MedicalDataSource`
val medicalDataSource: MedicalDataSource =
    healthConnectClient.createMedicalDataSource(
        CreateMedicalDataSourceRequest(
            fhirBaseUri = Uri.parse("https://fhir.com/oauth/api/FHIR/R4/"),
            displayName = "Test Data Source",
            fhirVersion = FhirVersion(4, 0, 1),
        )
    )

// Insert `MedicalResource`s into the `MedicalDataSource`
val medicalResources: List<MedicalResource> =
    healthConnectClient.upsertMedicalResources(
        listOf(
            UpsertMedicalResourceRequest(
                medicalDataSource.id,
                medicalDataSource.fhirVersion,
                medicationJsonToInsert, // a valid FHIR json string
            )
        )
    )

// Delete `MedicalResource`s matching the specified `dataSourceId`, `type` and `fhirResourceId`
healthConnectClient.deleteMedicalResources(
    medicalResources.map { medicalResource: MedicalResource ->
        MedicalResourceId(
            dataSourceId = medicalDataSource.id,
            fhirResourceType = medicalResource.id.fhirResourceType,
            fhirResourceId = medicalResource.id.fhirResourceId,
        )
    }
)
```

| Parameters |
|---|---|
| `ids: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId>` | The ids to delete. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException.html` | if caller does not hold `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()`. |

### deleteMedicalResources

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
@RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA")
@ExperimentalPersonalHealthRecordApi
open suspend fun deleteMedicalResources(request: DeleteMedicalResourcesRequest): Unit
```

Deletes `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s based on given filters in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/DeleteMedicalResourcesRequest`.

Only `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s inserted by the calling app will be deleted. If the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteMedicalResources(androidx.health.connect.client.request.DeleteMedicalResourcesRequest)` matches any other `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s, these will be ignored.

Regarding permissions:

- Caller must hold `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` in order to call this API.

- Deletes are permitted in the foreground or background.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#getFeatureStatus(kotlin.Int)` and pass `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#FEATURE_PERSONAL_HEALTH_RECORD()` as an argument. An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` would be thrown if the feature is not available.

```kotlin
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_PERSONAL_HEALTH_RECORD
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_STATUS_AVAILABLE
import androidx.health.connect.client.records.FhirVersion
import androidx.health.connect.client.records.MedicalDataSource
import androidx.health.connect.client.records.MedicalResource
import androidx.health.connect.client.records.MedicalResource.Companion.MEDICAL_RESOURCE_TYPE_MEDICATIONS
import androidx.health.connect.client.request.CreateMedicalDataSourceRequest
import androidx.health.connect.client.request.DeleteMedicalResourcesRequest
import androidx.health.connect.client.request.UpsertMedicalResourceRequest

// Ensure `FEATURE_PERSONAL_HEALTH_RECORD` is available before calling PHR apis
if (
    healthConnectClient.features.getFeatureStatus(FEATURE_PERSONAL_HEALTH_RECORD) !=
        FEATURE_STATUS_AVAILABLE
) {
    return
}

// Get or create a `MedicalDataSource`
val medicalDataSource: MedicalDataSource =
    healthConnectClient.createMedicalDataSource(
        CreateMedicalDataSourceRequest(
            fhirBaseUri = Uri.parse("https://fhir.com/oauth/api/FHIR/R4/"),
            displayName = "Test Data Source",
            fhirVersion = FhirVersion(4, 0, 1),
        )
    )

// Insert `MedicalResource`s into the `MedicalDataSource`
val medicalResources: List<MedicalResource> =
    healthConnectClient.upsertMedicalResources(
        listOf(
            UpsertMedicalResourceRequest(
                medicalDataSource.id,
                medicalDataSource.fhirVersion,
                medicationJsonToInsert, // a valid FHIR json string
            )
        )
    )

// Delete all `MedicalResource`s that are in any pair of provided `dataSourceIds` and
// `medicalResourceTypes`
healthConnectClient.deleteMedicalResources(
    DeleteMedicalResourcesRequest(
        dataSourceIds = setOf(medicalDataSource.id),
        medicalResourceTypes = setOf(MEDICAL_RESOURCE_TYPE_MEDICATIONS),
    )
)
```

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/DeleteMedicalResourcesRequest` | The request that contains the filters to delete. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException.html` | if caller does not hold `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()`. |

### deleteRecords

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
suspend fun deleteRecords(
    recordType: KClass<Record>,
    timeRangeFilter: TimeRangeFilter
): Unit
```

Deletes any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` of the given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,androidx.health.connect.client.time.TimeRangeFilter)` in the given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,androidx.health.connect.client.time.TimeRangeFilter)` (automatically filtered to `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` belonging to the calling application). Deletion of multiple `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` is executed in a transaction - if one fails, none is deleted.

```kotlin
import androidx.health.connect.client.deleteRecords
import androidx.health.connect.client.records.StepsRecord
import androidx.health.connect.client.time.TimeRangeFilter

healthConnectClient.deleteRecords<StepsRecord>(
    timeRangeFilter = TimeRangeFilter.between(startTime, endTime)
)
```

| Parameters |
|---|---|
| `recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>` | Which type of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete, such as `StepsRecord::class` |
| `timeRangeFilter: https://developer.android.com/reference/kotlin/androidx/health/connect/client/time/TimeRangeFilter` | The `https://developer.android.com/reference/kotlin/androidx/health/connect/client/time/TimeRangeFilter` to delete from |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. Example usage to delete written steps data in a time range: |

### deleteRecords

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
suspend fun deleteRecords(
    recordType: KClass<Record>,
    recordIdsList: List<String>,
    clientRecordIdsList: List<String>
): Unit
```

Deletes one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` by their identifiers. Deletion of multiple `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` is executed in single transaction - if one fails, none is deleted.

```kotlin
import androidx.health.connect.client.deleteRecords
import androidx.health.connect.client.records.StepsRecord

healthConnectClient.deleteRecords<StepsRecord>(
    recordIdsList = listOf(uid1, uid2),
    clientRecordIdsList = emptyList(),
)
```

| Parameters |
|---|---|
| `recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>` | Which type of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete, such as `Steps::class` |
| `recordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | List of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#id()` of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete |
| `clientRecordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | List of client record IDs of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. Deleting by invalid identifiers such as a non-existing identifier or deleting the same record multiple times will result in IPC failure. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. Example usage to delete written steps data by its unique identifier: |

### getChanges

```
suspend fun getChanges(changesToken: String): ChangesResponse
```

Retrieves changes in Health Connect, from a specific point in time represented by provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)`.

The response returned may not provide all the changes due to IPC or memory limits, see `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse#hasMore()`. Clients can make more api calls to fetch more changes from Health Connect with updated `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse#nextChangesToken()`.

Provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)` may have expired if clients have not synced for extended period of time (such as a month). In this case `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse#changesTokenExpired()` will be set, and clients should generate a new changes-token via `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChangesToken(androidx.health.connect.client.request.ChangesTokenRequest)`.

```kotlin
val response = client.getChanges(changesToken)
if (response.changesTokenExpired) {
  // Consider re-sync and fetch new changes token.
} else {
  // Process new insertion/deletions, either update local storage or upload to backends.
}
```

| Parameters |
|---|---|
| `changesToken: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | A changes token that represents a specific point in time in Android Health Platform. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` | a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` with changes since provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChangesToken(androidx.health.connect.client.request.ChangesTokenRequest)` |   |

### getChanges

```
suspend fun getChanges(changesToken: String, pageSize: @IntRange(from = 1, to = 5000) Int): ChangesResponse
```

Same as `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)` method but also allows specifying a preferred `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)`.

`https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)` is a soft limit that serves as a recommendation to the system. The system makes best attempt to limit the number of returned change logs, however in certain cases the response might exceed the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)`.

| Parameters |
|---|---|
| `changesToken: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | A changes token that represents a specific point in time in Android Health Platform. |
| `pageSize: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 5000) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The (soft) limit of change logs to return, must be within 1, 5000. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` | a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` with changes since provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChangesToken(androidx.health.connect.client.request.ChangesTokenRequest)` |   |

### getChangesToken

```
suspend fun getChangesToken(request: ChangesTokenRequest): String
```

Retrieves a changes-token, representing a point in time in the underlying Android Health Platform for a given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ChangesTokenRequest`. Changes-tokens are used in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)` to retrieve changes since that point in time.

Changes-tokens represent a point in time after which the client is interested in knowing the changes for a set of interested types of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` and optional `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/DataOrigin` filters.

Changes-tokens are only valid for 30 days after they're generated. Calls to `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)` with an expired changes-token will lead to `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse#changesTokenExpired()`

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ChangesTokenRequest` | Includes interested types of record to observe changes and optional filters. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | a changes-token |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)` |   |

### getMedicalDataSources

```
@ExperimentalPersonalHealthRecordApi
open suspend fun getMedicalDataSources(ids: List<String>): List<MedicalDataSource>
```

Gets `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s for the provided list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource#id()`.

The returned list of data sources will be in the same order as the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getMedicalDataSources(kotlin.collections.List)`.

Number of data sources returned by this API will depend based on below factors:

- If an empty list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getMedicalDataSources(kotlin.collections.List)` is provided, no data sources will be returned.

- If an id is invalid or non-existent, no data source will be returned for that id, this means the returned list might have fewer elements than `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getMedicalDataSources(kotlin.collections.List)`.

- Callers will only get data sources they are permitted to get. See below.

There is no specific read permission for getting data sources. Instead, permission to read data sources is based on whether the caller has permission to read the data currently contained in that data source. Being permitted to get data sources is dependent on the following logic, in priority order, earlier statements take precedence.

- A caller without any read medical permissions such as `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_MEDICAL_DATA_VACCINES()` or the write permission `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` is not permitted get any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s, including ones that it created.

- A caller with the write permission is permitted to read its own `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s regardless whether it's in foreground or background.

- A caller with only a read permission, when in background, is only permitted to read its own `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s that contains at least one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` with the type that the read permission covers. However, when the caller is in foreground or if it holds `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND()`, it can also read other apps' `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s as long as each of those `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` contains at least one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` with the corresponding type.

  - For example, if a caller `A` created a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` `DS1`, then used `DS1` to insert a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` `MR1` with type `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource#MEDICAL_RESOURCE_TYPE_VACCINES()`, and another caller `B` created `DS2`. If `A` holds `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_MEDICAL_DATA_VACCINES()`, it can only read `DS1` in background. However, if it is in foreground or holds `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND()`, it can read both `DS1` and `DS2`.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#getFeatureStatus(kotlin.Int)` and pass `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#FEATURE_PERSONAL_HEALTH_RECORD()` as an argument. An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` would be thrown if the feature is not available.

```kotlin
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_PERSONAL_HEALTH_RECORD
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_STATUS_AVAILABLE
import androidx.health.connect.client.records.FhirVersion
import androidx.health.connect.client.records.MedicalDataSource
import androidx.health.connect.client.request.CreateMedicalDataSourceRequest

// Ensure `FEATURE_PERSONAL_HEALTH_RECORD` is available before calling PHR apis
if (
    healthConnectClient.features.getFeatureStatus(FEATURE_PERSONAL_HEALTH_RECORD) !=
        FEATURE_STATUS_AVAILABLE
) {
    return
}

// Get or create a `MedicalDataSource`
// Each `MedicalDataSource` is assigned an `id` by the system on creation
val medicalDataSource: MedicalDataSource =
    healthConnectClient.createMedicalDataSource(
        CreateMedicalDataSourceRequest(
            fhirBaseUri = Uri.parse("https://fhir.com/oauth/api/FHIR/R4/"),
            displayName = "Test Data Source",
            fhirVersion = FhirVersion(4, 0, 1),
        )
    )

// Retrieve all `MedicalDataSource` with `id` matching any of the given ids
val medicalDataSources: List<MedicalDataSource> =
    healthConnectClient.getMedicalDataSources(listOf(medicalDataSource.id, anotherId))
```

| Parameters |
|---|---|
| `ids: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | ids of the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s to retrieve |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource>` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s matching the provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getMedicalDataSources(kotlin.collections.List)` |

### getMedicalDataSources

```
@ExperimentalPersonalHealthRecordApi
open suspend fun getMedicalDataSources(request: GetMedicalDataSourcesRequest): List<MedicalDataSource>
```

Gets the requested `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s using `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/GetMedicalDataSourcesRequest`. Number of data sources returned by this API will depend based on below factors:

- If an empty `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/GetMedicalDataSourcesRequest` is passed, all data sources for all apps are requested, and all which the caller is permitted to get will be returned. See below.

- If `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/GetMedicalDataSourcesRequest#packageNames()` is not empty, then only the data sources created by those packages is being requested. All data sources created by those packages which the caller is permitted to get will be returned. See below.

There is no specific read permission for getting data sources. Instead, permission to read data sources is based on whether the caller has permission to read the data currently contained in that data source. Specifically:

- A caller without any read medical permissions such as `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_MEDICAL_DATA_VACCINES()` or the write permission `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` is not permitted get any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s, including ones that it created.

- A caller with the write permission is permitted to read its own `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s regardless whether it's in foreground or background.

- A caller with only a read permission, when in background, is only permitted to read its own `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s that contains at least one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` with the type that the read permission covers. However, when the caller is in foreground or if it holds `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND()`, it can also read other apps' `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s as long as each of those `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` contains at least one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` with the corresponding type.

  - For example, a client `A` created a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` `DS1`, then used `DS1` to insert a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` `MR1` with type `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource#MEDICAL_RESOURCE_TYPE_VACCINES()`. Similarly another client `B` created `DS2`, then used `DS2` to insert another `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` `MR2` with the same `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource#MEDICAL_RESOURCE_TYPE_VACCINES()`. If `A` holds `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_MEDICAL_DATA_VACCINES()` and it is in background, it can only read `DS1`. However, if `A` is in foreground or holds `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND()`, it can read both `DS1` and `DS2`.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#getFeatureStatus(kotlin.Int)` and pass `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#FEATURE_PERSONAL_HEALTH_RECORD()` as an argument. An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` would be thrown if the feature is not available.

```kotlin
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_PERSONAL_HEALTH_RECORD
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_STATUS_AVAILABLE
import androidx.health.connect.client.records.FhirVersion
import androidx.health.connect.client.records.MedicalDataSource
import androidx.health.connect.client.request.CreateMedicalDataSourceRequest
import androidx.health.connect.client.request.GetMedicalDataSourcesRequest

// Ensure `FEATURE_PERSONAL_HEALTH_RECORD` is available before calling PHR apis
if (
    healthConnectClient.features.getFeatureStatus(FEATURE_PERSONAL_HEALTH_RECORD) !=
        FEATURE_STATUS_AVAILABLE
) {
    return
}

// Get or create a `MedicalDataSource`
// Each `MedicalDataSource` contains the `packageName` which created it
val medicalDataSource: MedicalDataSource =
    healthConnectClient.createMedicalDataSource(
        CreateMedicalDataSourceRequest(
            fhirBaseUri = Uri.parse("https://fhir.com/oauth/api/FHIR/R4/"),
            displayName = "Test Data Source",
            fhirVersion = FhirVersion(4, 0, 1),
        )
    )

// Retrieve all `MedicalDataSource`s created by any of the specified package names
// Package names may be found in other `MedicalDataSource`s or from arbitrary input
val medicalDataSources: List<MedicalDataSource> =
    healthConnectClient.getMedicalDataSources(
        GetMedicalDataSourcesRequest(listOf(medicalDataSource.packageName, anotherPackageName))
    )
```

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/GetMedicalDataSourcesRequest` | containing details of the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s to retrieve |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource>` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s matching the provided request |

### insertRecords

```
suspend fun insertRecords(records: List<Record>): InsertRecordsResponse
```

Inserts one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` and returns newly assigned `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#id()` generated. Insertion of multiple `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#insertRecords(kotlin.collections.List)` is executed in a transaction - if one fails, none is inserted.

```kotlin
import androidx.health.connect.client.records.StepsRecord
import androidx.health.connect.client.records.metadata.Metadata

val stepsRecord =
    StepsRecord(
        count = 120,
        startTime = START_TIME,
        endTime = END_TIME,
        startZoneOffset = START_ZONE_OFFSET,
        endZoneOffset = END_ZONE_OFFSET,
        metadata = Metadata.manualEntry(),
    )
healthConnectClient.insertRecords(listOf(stepsRecord))
```

To insert more complex data like nutrition for a user who's eaten a banana:

```kotlin
import androidx.health.connect.client.records.NutritionRecord
import androidx.health.connect.client.records.metadata.Metadata
import androidx.health.connect.client.units.grams
import androidx.health.connect.client.units.kilocalories

val banana =
    NutritionRecord(
        name = "banana",
        energy = 105.0.kilocalories,
        dietaryFiber = 3.1.grams,
        potassium = 0.422.grams,
        totalCarbohydrate = 27.0.grams,
        totalFat = 0.4.grams,
        saturatedFat = 0.1.grams,
        sodium = 0.001.grams,
        sugar = 14.0.grams,
        vitaminB6 = 0.0005.grams,
        vitaminC = 0.0103.grams,
        startTime = START_TIME,
        endTime = END_TIME,
        startZoneOffset = START_ZONE_OFFSET,
        endZoneOffset = END_ZONE_OFFSET,
        metadata = Metadata.manualEntry(),
    )
healthConnectClient.insertRecords(listOf(banana))
```

To insert some heart rate data:

```kotlin
import androidx.health.connect.client.records.HeartRateRecord
import androidx.health.connect.client.records.metadata.Metadata

val heartRateRecord =
    HeartRateRecord(
        startTime = START_TIME,
        startZoneOffset = START_ZONE_OFFSET,
        endTime = END_TIME,
        endZoneOffset = END_ZONE_OFFSET,
        metadata = Metadata.manualEntry(),
        // records 10 arbitrary data, to replace with actual data
        samples =
            List(10) { index ->
                HeartRateRecord.Sample(
                    time = START_TIME + Duration.ofSeconds(index.toLong()),
                    beatsPerMinute = 100 + index.toLong(),
                )
            },
    )
healthConnectClient.insertRecords(listOf(heartRateRecord))
```

`https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#clientRecordId()` can be used to deduplicate data with a client provided unique identifier. When a subsequent `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#insertRecords(kotlin.collections.List)` is called with the same `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#clientRecordId()`, whichever `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` with the higher `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#clientRecordVersion()` takes precedence.

| Parameters |
|---|---|
| `records: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>` | List of records to insert |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/InsertRecordsResponse` | List of unique identifiers in the order of inserted records. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. For example, to insert basic data like step counts: |

### readMedicalResources

```
@ExperimentalPersonalHealthRecordApi
open suspend fun readMedicalResources(ids: List<MedicalResourceId>): List<MedicalResource>
```

Reads a collection of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s given a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId`s.

The number and order of medical resources returned by this API is not guaranteed, depending on a number of factors:

- If an empty list of IDs is provided, an empty list will be returned.

- If any ID does not exist, no medical resource will be returned for that ID.

- Only permitted `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s are returned. Specifically:

  - A caller without any read medical permissions such as `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_MEDICAL_DATA_VACCINES()`, or the write medical permission `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` is not permitted to read any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`, including ones that it created.

  - A caller with the write permission is permitted to read its own `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s of any type regardless whether it's in foreground or background.

  - A caller with only a read permission, when in background, is only permitted to read its own `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s of the corresponding type. For example, if a caller only holds `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_MEDICAL_DATA_VACCINES()`, then when in background it is only permitted to read its own `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s with `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource#MEDICAL_RESOURCE_TYPE_VACCINES()`. However, when it is in foreground or if it holds `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND()`, it is permitted to read all vaccines `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s, including ones that were written by other apps.

Each returned `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` is not guaranteed to meet all requirements of the [Fast Healthcare Interoperability Resources (FHIR) spec]("https://hl7.org/fhir/resourcelist.html"). If required, clients should perform their own validations.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#getFeatureStatus(kotlin.Int)` and pass `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#FEATURE_PERSONAL_HEALTH_RECORD()` as an argument. An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` would be thrown if the feature is not available.

```kotlin
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_PERSONAL_HEALTH_RECORD
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_STATUS_AVAILABLE
import androidx.health.connect.client.records.FhirVersion
import androidx.health.connect.client.records.MedicalDataSource
import androidx.health.connect.client.records.MedicalResource
import androidx.health.connect.client.records.MedicalResourceId
import androidx.health.connect.client.request.CreateMedicalDataSourceRequest
import androidx.health.connect.client.request.UpsertMedicalResourceRequest

// Ensure `FEATURE_PERSONAL_HEALTH_RECORD` is available before calling PHR apis
if (
    healthConnectClient.features.getFeatureStatus(FEATURE_PERSONAL_HEALTH_RECORD) !=
        FEATURE_STATUS_AVAILABLE
) {
    return
}

// Get or create a `MedicalDataSource`
val medicalDataSource: MedicalDataSource =
    healthConnectClient.createMedicalDataSource(
        CreateMedicalDataSourceRequest(
            fhirBaseUri = Uri.parse("https://fhir.com/oauth/api/FHIR/R4/"),
            displayName = "Test Data Source",
            fhirVersion = FhirVersion(4, 0, 1),
        )
    )

// Insert `MedicalResource`s into the `MedicalDataSource`
val medicalResources: List<MedicalResource> =
    healthConnectClient.upsertMedicalResources(
        listOf(
            UpsertMedicalResourceRequest(
                medicalDataSource.id,
                medicalDataSource.fhirVersion,
                medicationJsonToInsert, // a valid FHIR json string
            )
        )
    )

// Retrieve `fhirResourceType` type `MedicalResource`s with the specified `id`s from the
// provided `MedicalDataSource`
val retrievedMedicalResources: List<MedicalResource> =
    healthConnectClient.readMedicalResources(
        medicalResources.map { medicalResource: MedicalResource ->
            MedicalResourceId(
                dataSourceId = medicalDataSource.id,
                fhirResourceType = medicalResource.id.fhirResourceType,
                fhirResourceId = medicalResource.id.fhirResourceId,
            )
        }
    )
```

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the size of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readMedicalResources(kotlin.collections.List)` is too large or any ID is deemed as invalid. |

### readMedicalResources

```
@ExperimentalPersonalHealthRecordApi
open suspend fun readMedicalResources(request: ReadMedicalResourcesRequest): ReadMedicalResourcesResponse
```

Reads `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s by request, either `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadMedicalResourcesInitialRequest` or `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadMedicalResourcesPageRequest`.

A typical flow to read all `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s that satisfy a certain criteria would be:

1. Create a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadMedicalResourcesInitialRequest` with desired criteria, and make a request. If successful, a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadMedicalResourcesResponse` should be returned.

2. Use returned `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadMedicalResourcesResponse#nextPageToken()` to create a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadMedicalResourcesPageRequest` and make another request. Again, if successful, a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadMedicalResourcesResponse` should be returned.

3. Repeat step 2 until `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadMedicalResourcesResponse#nextPageToken()` is null.

Regarding permissions, only permitted `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s are returned. Specifically:

- A caller without any read medical permissions such as `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_MEDICAL_DATA_VACCINES()`, or the write medical permission `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` is not permitted to read any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`, including ones that it created.

- A caller with the write permission is permitted to read its own `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s of any type regardless whether it's in foreground or background.

- A caller with only a read permission, when in background, is only permitted to read its own `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s of the corresponding type. For example, if a caller only holds `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_MEDICAL_DATA_VACCINES()`, then when in background it is only permitted to read its own `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s with `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource#MEDICAL_RESOURCE_TYPE_VACCINES()`. However, when it is in foreground or if it holds `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND()`, it is permitted to read all vaccines `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s, including ones that were written by other apps.

Each returned `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` is not guaranteed to meet all requirements of the [Fast Healthcare Interoperability Resources (FHIR) spec]("https://hl7.org/fhir/resourcelist.html"). If required, clients should perform their own validations.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#getFeatureStatus(kotlin.Int)` and pass `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#FEATURE_PERSONAL_HEALTH_RECORD()` as an argument. An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` would be thrown if the feature is not available.

```kotlin
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_PERSONAL_HEALTH_RECORD
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_STATUS_AVAILABLE
import androidx.health.connect.client.records.FhirVersion
import androidx.health.connect.client.records.MedicalDataSource
import androidx.health.connect.client.records.MedicalResource
import androidx.health.connect.client.records.MedicalResource.Companion.MEDICAL_RESOURCE_TYPE_LABORATORY_RESULTS
import androidx.health.connect.client.request.CreateMedicalDataSourceRequest
import androidx.health.connect.client.request.ReadMedicalResourcesInitialRequest
import androidx.health.connect.client.request.ReadMedicalResourcesPageRequest
import androidx.health.connect.client.request.ReadMedicalResourcesRequest
import androidx.health.connect.client.response.ReadMedicalResourcesResponse

// Ensure `FEATURE_PERSONAL_HEALTH_RECORD` is available before calling PHR apis
if (
    healthConnectClient.features.getFeatureStatus(FEATURE_PERSONAL_HEALTH_RECORD) !=
        FEATURE_STATUS_AVAILABLE
) {
    return
}

// Get or create a `MedicalDataSource`
val medicalDataSource: MedicalDataSource =
    healthConnectClient.createMedicalDataSource(
        CreateMedicalDataSourceRequest(
            fhirBaseUri = Uri.parse("https://fhir.com/oauth/api/FHIR/R4/"),
            displayName = "Test Data Source",
            fhirVersion = FhirVersion(4, 0, 1),
        )
    )

// Insert `MedicalResource`s into the `MedicalDataSource`
healthConnectClient.upsertMedicalResources(exampleLabResults)

// Read `MedicalResource`s back from the `MedicalDataSource`
// Read 100 resources / page. See `pageSize` doc for defaults and limits.
val pageSize = 100
// Prepare the initial read request.
// All `MedicalResource`s in the given `MedicalDataSource`s and of given `medicalResourceType`
// will be retrieved.
val initialRequest: ReadMedicalResourcesRequest =
    ReadMedicalResourcesInitialRequest(
        MEDICAL_RESOURCE_TYPE_LABORATORY_RESULTS,
        setOf(medicalDataSource.id),
        pageSize = pageSize,
    )
// Continue reading pages until all `MedicalResource`s are read
var pageToken: String? = null
do {
    // Prepare paged request if needed
    val request: ReadMedicalResourcesRequest =
        if (pageToken == null) initialRequest
        else ReadMedicalResourcesPageRequest(pageToken, pageSize = pageSize)
    // Read `MedicalResource`s
    val response: ReadMedicalResourcesResponse =
        healthConnectClient.readMedicalResources(request)
    // Process `MedicalResource`s as desired
    val resources: List<MedicalResource> = response.medicalResources
    // Advance to next page
    pageToken = response.nextPageToken
} while (pageToken != null)
```

### readRecord

```
suspend fun <T : Record> readRecord(recordType: KClass<T>, recordId: String): ReadRecordResponse<T>
```

Reads one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` point with its `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readRecord(kotlin.reflect.KClass,kotlin.String)` and `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readRecord(kotlin.reflect.KClass,kotlin.String)`.

| Parameters |
|---|---|
| `recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<T>` | Which type of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to read, such as `Steps::class` |
| `recordId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#id()` of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to read |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadRecordResponse<T>` | The `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` data point. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. Update with invalid identifiers will result in IPC failure. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. |

### readRecords

```
suspend fun <T : Record> readRecords(request: ReadRecordsRequest<T>): ReadRecordsResponse<T>
```

Retrieves a collection of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record`s.

```kotlin
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 response =
    healthConnectClient.readRecords(
        ReadRecordsRequest<StepsRecord>(
            timeRangeFilter = TimeRangeFilter.between(startTime, endTime)
        )
    )
for (stepRecord in response.records) {
    // Process each step record
}
```

| Parameters |
|---|---|
| `<T : https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>` | the type of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` |
| `request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadRecordsRequest<T>` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadRecordsRequest` object specifying time range and other filters |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadRecordsResponse<T>` | a response containing a collection of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record`s. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. Example code to read basic data like step counts: |

### updateRecords

```
suspend fun updateRecords(records: List<Record>): Unit
```

Updates one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` of given UIDs to newly specified values. Update of multiple `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#updateRecords(kotlin.collections.List)` is executed in a transaction - if one fails, none is inserted.

| Parameters |
|---|---|
| `records: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>` | List of records to update |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. Update with invalid identifiers will result in IPC failure. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. |

### upsertMedicalResources

```
@RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA")
@ExperimentalPersonalHealthRecordApi
open suspend fun upsertMedicalResources(requests: List<UpsertMedicalResourceRequest>): List<MedicalResource>
```

Inserts or updates a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s using `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest`s.

In each request, from `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest#dataSourceId()`, fhir resource type and fhir resource ID extracted from `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest#data()`, a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId` will be constructed. If there already exists a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` with that ID in Health Connect, then it will be updated, otherwise a new `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` will be inserted.

For each `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest`, one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource` will be returned, regardless whether it's updated or inserted. The order of the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s in the returned list will be the same as their corresponding `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest`s in the input list.

Note that a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` needs to be created using `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#createMedicalDataSource(androidx.health.connect.client.request.CreateMedicalDataSourceRequest)` before any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s can be upserted for this source.

Regarding permissions:

- Caller must hold `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` in order to call this API, otherwise a `https://developer.android.com/reference/java/lang/SecurityException.html` will be thrown.

- With `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()` granted, caller is permitted to call this API in either foreground or background.

Medical data is represented using the "https://hl7.org/fhir/" standard. The FHIR resource provided in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest#data()` is expected to be valid for the specified `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest#fhirVersion()` according to the [FHIR spec](https://hl7.org/fhir/resourcelist.html). Structural validation checks such as resource structure, field types and presence of required fields will be performed, however these checks may not cover all FHIR spec requirements and are dependant on the backing implementation of Health Connect.

Data written to Health Connect should be for a single individual only. However, the API allows for multiple Patient resources to be written to account for the possibility of multiple Patient resources being present in one individual's medical record.

Each `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest` also has to meet the following requirements:

- `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest#data()` must contain an "id" field and a "resourceType" field. The "resource type" must be one of the items in the accepted list of resource types in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/FhirResource`.

- The FHIR resource does not have a "contained" field (holds [contained resources](https://build.fhir.org/references.html#contained)).

- `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest#fhirVersion()` of each request must match `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource#fhirVersion()` of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest#dataSourceId()`'s corresponding `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`.

If any request is failed to be processed for any reason, none of the requests will be inserted or updated in one transaction.

This feature is dependent on the version of HealthConnect installed on the device. To check if it's available call `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#getFeatureStatus(kotlin.Int)` and pass `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures#FEATURE_PERSONAL_HEALTH_RECORD()` as an argument. An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` would be thrown if the feature is not available.

```kotlin
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_PERSONAL_HEALTH_RECORD
import androidx.health.connect.client.HealthConnectFeatures.Companion.FEATURE_STATUS_AVAILABLE
import androidx.health.connect.client.records.FhirVersion
import androidx.health.connect.client.records.MedicalDataSource
import androidx.health.connect.client.records.MedicalResource
import androidx.health.connect.client.request.CreateMedicalDataSourceRequest
import androidx.health.connect.client.request.UpsertMedicalResourceRequest

// Ensure `FEATURE_PERSONAL_HEALTH_RECORD` is available before calling PHR apis
if (
    healthConnectClient.features.getFeatureStatus(FEATURE_PERSONAL_HEALTH_RECORD) !=
        FEATURE_STATUS_AVAILABLE
) {
    return
}

// Get or create a `MedicalDataSource`
val medicalDataSource: MedicalDataSource =
    healthConnectClient.createMedicalDataSource(
        CreateMedicalDataSourceRequest(
            fhirBaseUri = Uri.parse("https://fhir.com/oauth/api/FHIR/R4/"),
            displayName = "Test Data Source",
            fhirVersion = FhirVersion(4, 0, 1),
        )
    )

// Insert `MedicalResource`s into the `MedicalDataSource`
val medicalResources: List<MedicalResource> =
    healthConnectClient.upsertMedicalResources(
        listOf(
            UpsertMedicalResourceRequest(
                medicalDataSource.id,
                medicalDataSource.fhirVersion,
                medicationJsonToInsert, // a valid FHIR json string
            )
        )
    )

// Update `MedicalResource`s in the `MedicalDataSource`
val updatedMedicalResources: List<MedicalResource> =
    healthConnectClient.upsertMedicalResources(
        listOf(
            UpsertMedicalResourceRequest(
                medicalDataSource.id,
                medicalDataSource.fhirVersion,
                // a valid FHIR json string
                // if this resource has the same type and ID as in `medicationJsonToInsert`,
                // this `upsertMedicalResources()` call will update the previously inserted
                // `MedicalResource`
                updatedMedicationJsonToInsert,
            )
        )
    )
```

| Parameters |
|---|---|
| `requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest>` | List of upsert requests. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if any request is failed to be processed for any reason such as invalid `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest#dataSourceId()` |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | if caller does not hold `https://developer.android.com/reference/kotlin/androidx/health/connect/client/permission/HealthPermission#PERMISSION_WRITE_MEDICAL_DATA()`. |

## Public properties

### features

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
open val features: HealthConnectFeatures
```

Access operations related to feature availability.

### permissionController

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
val permissionController: PermissionController
```

Access operations related to permissions.

## Extension functions

### HealthConnectClient.deleteRecords

Artifact: [androidx.health.connect:connect-client](https://developer.android.com/jetpack/androidx/releases/health-connect) [View Source](https://cs.android.com/search?q=file:androidx/health/connect/client/HealthConnectClientExt.kt+function:deleteRecords)

```
suspend inline fun <T : Record> HealthConnectClient.deleteRecords(
    timeRangeFilter: TimeRangeFilter
): Unit
```

Deletes any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` of type `https://developer.android.com/reference/kotlin/androidx/health/connect/client/package-summary#(androidx.health.connect.client.HealthConnectClient).deleteRecords(androidx.health.connect.client.time.TimeRangeFilter)` in the given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/package-summary#(androidx.health.connect.client.HealthConnectClient).deleteRecords(androidx.health.connect.client.time.TimeRangeFilter)` (automatically filtered to `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` belonging to the calling application). Deletion of multiple `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` is executed in a transaction - if one fails, none is deleted.

```kotlin
import androidx.health.connect.client.deleteRecords
import androidx.health.connect.client.records.StepsRecord
import androidx.health.connect.client.time.TimeRangeFilter

healthConnectClient.deleteRecords<StepsRecord>(
    timeRangeFilter = TimeRangeFilter.between(startTime, endTime)
)
```

| Parameters |
|---|---|
| `<T : https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>` | Which type of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete, such as `StepsRecord`. |
| `timeRangeFilter: https://developer.android.com/reference/kotlin/androidx/health/connect/client/time/TimeRangeFilter` | The `https://developer.android.com/reference/kotlin/androidx/health/connect/client/time/TimeRangeFilter` to delete from |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If service is not available. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,kotlin.collections.List,kotlin.collections.List)` | Example usage to delete written steps data in a time range: |

### HealthConnectClient.deleteRecords

Artifact: [androidx.health.connect:connect-client](https://developer.android.com/jetpack/androidx/releases/health-connect) [View Source](https://cs.android.com/search?q=file:androidx/health/connect/client/HealthConnectClientExt.kt+function:deleteRecords)

```
suspend inline fun <T : Record> HealthConnectClient.deleteRecords(
    recordIdsList: List<String>,
    clientRecordIdsList: List<String>
): Unit
```

Deletes one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` by their identifiers. Deletion of multiple `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` is executed in single transaction - if one fails, none is deleted.

```kotlin
import androidx.health.connect.client.deleteRecords
import androidx.health.connect.client.records.StepsRecord

healthConnectClient.deleteRecords<StepsRecord>(
    recordIdsList = listOf(uid1, uid2),
    clientRecordIdsList = emptyList(),
)
```

| Parameters |
|---|---|
| `<T : https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>` | Which type of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete, such as `StepsRecord`. |
| `recordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | List of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#id()` of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete |
| `clientRecordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | List of client record IDs of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. Deleting by invalid identifiers such as a non-existing identifier or deleting the same record multiple times will result in IPC failure. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If service is not available. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,kotlin.collections.List,kotlin.collections.List)` | Example usage to delete written steps data by its unique identifier: |

### HealthConnectClient.readRecord

Artifact: [androidx.health.connect:connect-client](https://developer.android.com/jetpack/androidx/releases/health-connect) [View Source](https://cs.android.com/search?q=file:androidx/health/connect/client/HealthConnectClientExt.kt+function:readRecord)

```
suspend inline fun <T : Record> HealthConnectClient.readRecord(recordId: String): ReadRecordResponse<T>
```

Reads one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` point of type `https://developer.android.com/reference/kotlin/androidx/health/connect/client/package-summary#(androidx.health.connect.client.HealthConnectClient).readRecord(kotlin.String)` and with the specified `https://developer.android.com/reference/kotlin/androidx/health/connect/client/package-summary#(androidx.health.connect.client.HealthConnectClient).readRecord(kotlin.String)`.

| Parameters |
|---|---|
| `<T : https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>` | Which type of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to read, such as `StepsRecord`. |
| `recordId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#id()` of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to read |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadRecordResponse<T>` | The `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` data point. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. Update with invalid identifiers will result in IPC failure. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If service is not available. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readRecord(kotlin.reflect.KClass,kotlin.String)` |   |