Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions) Summary: [Constants](https://developer.android.com/reference/android/health/connect/HealthConnectManager#constants) \| [Methods](https://developer.android.com/reference/android/health/connect/HealthConnectManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/health/connect/HealthConnectManager#inhmethods)

# HealthConnectManager

*** ** * ** ***

` public class HealthConnectManager `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.health.connect.HealthConnectManager |

<br />

*** ** * ** ***

This class provides APIs to interact with the centralized HealthConnect storage maintained by the system.

HealthConnect is an offline, on-device storage that unifies data from multiple devices and apps into an ecosystem featuring.

- APIs to insert data of various types into the system.

The basic unit of data in HealthConnect is represented as a `https://developer.android.com/reference/android/health/connect/datatypes/Record` object, which is the base class for all the other data types such as `https://developer.android.com/reference/android/health/connect/datatypes/StepsRecord`.

## Summary

| ### Constants ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/health/connect/HealthConnectManager#ACTION_MANAGE_HEALTH_PERMISSIONS` Activity action: Launch UI to manage (e.g. grant/revoke) health permissions. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/health/connect/HealthConnectManager#ACTION_REQUEST_EXERCISE_ROUTE` Activity action: Launch UI to share the route associated with an exercise session. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/health/connect/HealthConnectManager#ACTION_SHOW_ONBOARDING` Activity action: Launch activity exported by client application that handles onboarding to Health Connect. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/health/connect/HealthConnectManager#CATEGORY_HEALTH_PERMISSIONS` Used in conjunction with `https://developer.android.com/reference/android/content/Intent#ACTION_VIEW_PERMISSION_USAGE` to launch UI to show an app\\u2019s health permission rationale/data policy. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/health/connect/HealthConnectManager#EXTRA_EXERCISE_ROUTE` An exercise route requested via `https://developer.android.com/reference/android/health/connect/HealthConnectManager#ACTION_REQUEST_EXERCISE_ROUTE`. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/health/connect/HealthConnectManager#EXTRA_SESSION_ID` A string ID of a session to be used with `https://developer.android.com/reference/android/health/connect/HealthConnectManager#ACTION_REQUEST_EXERCISE_ROUTE`. |

| ### Public methods ||
|---|---|
| ` <T> void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#aggregate(android.health.connect.AggregateRecordsRequest<T>,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.AggregateRecordsResponse<T>,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/android/health/connect/AggregateRecordsRequest<T> request, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/health/connect/AggregateRecordsResponse<T>, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Get aggregations corresponding to `request`. |
| ` <T> void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#aggregateGroupByDuration(android.health.connect.AggregateRecordsRequest<T>,%20java.time.Duration,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.util.List<android.health.connect.AggregateRecordsGroupedByDurationResponse<T>>,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/android/health/connect/AggregateRecordsRequest<T> request, https://developer.android.com/reference/java/time/Duration duration, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/AggregateRecordsGroupedByDurationResponse<T>>, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Get aggregations corresponding to `request`. |
| ` <T> void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#aggregateGroupByPeriod(android.health.connect.AggregateRecordsRequest<T>,%20java.time.Period,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.util.List<android.health.connect.AggregateRecordsGroupedByPeriodResponse<T>>,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/android/health/connect/AggregateRecordsRequest<T> request, https://developer.android.com/reference/java/time/Period period, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/AggregateRecordsGroupedByPeriodResponse<T>>, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Get aggregations corresponding to `request`. |
| ` https://developer.android.com/reference/android/content/Intent` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#createMatchmakingIntent(android.health.connect.MatchmakingRequest)(https://developer.android.com/reference/android/health/connect/MatchmakingRequest request) ` Creates an `https://developer.android.com/reference/android/content/Intent` 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/android/health/connect/datatypes/Record` classes the calling app can read. <br /> |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#createMedicalDataSource(android.health.connect.CreateMedicalDataSourceRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.datatypes.MedicalDataSource,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/android/health/connect/CreateMedicalDataSourceRequest request, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Creates a `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource` in HealthConnect based on the `https://developer.android.com/reference/android/health/connect/CreateMedicalDataSourceRequest` request values. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#deleteMedicalDataSourceWithData(java.lang.String,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/lang/String id, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Void, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Deletes a `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource` and all data linked to it. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#deleteMedicalResources(java.util.List<android.health.connect.MedicalResourceId>,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/MedicalResourceId> ids, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Void, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Deletes a list of `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s by the provided list of `https://developer.android.com/reference/android/health/connect/MedicalResourceId`s. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#deleteMedicalResources(android.health.connect.DeleteMedicalResourcesRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/android/health/connect/DeleteMedicalResourcesRequest request, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Void, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Deletes `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s based on given filters in `https://developer.android.com/reference/android/health/connect/DeleteMedicalResourcesRequest`. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#deleteRecords(java.util.List<android.health.connect.RecordIdFilter>,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/RecordIdFilter> recordIds, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Void, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Deletes records based on `https://developer.android.com/reference/android/health/connect/RecordIdFilter`. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#deleteRecords(java.lang.Class<?%20extends%20android.health.connect.datatypes.Record>,%20android.health.connect.TimeRangeFilter,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/lang/Class<? extends https://developer.android.com/reference/android/health/connect/datatypes/Record> recordType, https://developer.android.com/reference/android/health/connect/TimeRangeFilter timeRangeFilter, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Void, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Deletes records based on the `https://developer.android.com/reference/android/health/connect/TimeRangeFilter`. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#getChangeLogToken(android.health.connect.changelog.ChangeLogTokenRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.changelog.ChangeLogTokenResponse,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/android/health/connect/changelog/ChangeLogTokenRequest request, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/health/connect/changelog/ChangeLogTokenResponse, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Get token for {HealthConnectManager#getChangeLogs}. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#getChangeLogs(android.health.connect.changelog.ChangeLogsRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.changelog.ChangeLogsResponse,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/android/health/connect/changelog/ChangeLogsRequest changeLogsRequest, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/health/connect/changelog/ChangeLogsResponse, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Get change logs post the time when `token` was generated. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#getCurrentDeviceDataSource(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.DeviceDataSource,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/health/connect/DeviceDataSource, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Retrieves the `https://developer.android.com/reference/android/health/connect/DeviceDataSource` for the current device. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#getDeviceDataSourceCapabilities(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.DeviceDataSourceCapabilities,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/health/connect/DeviceDataSourceCapabilities, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Returns a set of record type classes that device data sources are capable of providing. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#getDeviceDataSources(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.GetDeviceDataSourcesResponse,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/health/connect/GetDeviceDataSourcesResponse, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Retrieves the list of all `https://developer.android.com/reference/android/health/connect/DeviceDataSource`s. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#getMedicalDataSources(java.util.List<java.lang.String>,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.util.List<android.health.connect.datatypes.MedicalDataSource>,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/lang/String> ids, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource>, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Returns `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource`s for the provided list of IDs. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#getMedicalDataSources(android.health.connect.GetMedicalDataSourcesRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.util.List<android.health.connect.datatypes.MedicalDataSource>,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/android/health/connect/GetMedicalDataSourcesRequest request, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource>, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Returns the requested `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource`s. |
| ` static https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/Class<? extends https://developer.android.com/reference/android/health/connect/datatypes/Record>>` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#getPermissionSensitiveDeviceDataSourceCapabilities()() ` Returns the set of data types which are excluded from the output of #getDeviceDataSourceCapabilities unless the caller holds the read permission for those data types. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#insertRecords(java.util.List<android.health.connect.datatypes.Record>,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.InsertRecordsResponse,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/datatypes/Record> records, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/health/connect/InsertRecordsResponse, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Inserts `records` into the HealthConnect database. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#isMatchmakingPossible(android.health.connect.MatchmakingRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.MatchmakingResponse,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/android/health/connect/MatchmakingRequest request, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/health/connect/MatchmakingResponse, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Checks if launching the intent returned by `https://developer.android.com/reference/android/health/connect/HealthConnectManager#createMatchmakingIntent(android.health.connect.MatchmakingRequest)` with the same arguments will result in showing at least one matching data source. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#readMedicalResources(java.util.List<android.health.connect.MedicalResourceId>,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.util.List<android.health.connect.datatypes.MedicalResource>,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/MedicalResourceId> ids, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource>, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Reads `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s based on a list of `https://developer.android.com/reference/android/health/connect/MedicalResourceId`s. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#readMedicalResources(android.health.connect.ReadMedicalResourcesRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.ReadMedicalResourcesResponse,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/android/health/connect/ReadMedicalResourcesRequest request, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/health/connect/ReadMedicalResourcesResponse, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Reads `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s based on `https://developer.android.com/reference/android/health/connect/ReadMedicalResourcesInitialRequest` or `https://developer.android.com/reference/android/health/connect/ReadMedicalResourcesPageRequest`. |
| ` <T extends https://developer.android.com/reference/android/health/connect/datatypes/Record> void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#readRecords(android.health.connect.ReadRecordsRequest<T>,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.ReadRecordsResponse<T>,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/android/health/connect/ReadRecordsRequest<T> request, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/health/connect/ReadRecordsResponse<T>, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` API to read records based on `https://developer.android.com/reference/android/health/connect/ReadRecordsRequestUsingFilters` or `https://developer.android.com/reference/android/health/connect/ReadRecordsRequestUsingIds` Number of records returned by this API will depend based on below factors: When an app with read permission allowed calls the API from background then it will be able to read only its own inserted records and will not get records inserted by other apps. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#updateRecords(java.util.List<android.health.connect.datatypes.Record>,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/datatypes/Record> records, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Void, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Updates `records` into the HealthConnect database. |
| ` void` | ` https://developer.android.com/reference/android/health/connect/HealthConnectManager#upsertMedicalResources(java.util.List<android.health.connect.UpsertMedicalResourceRequest>,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.util.List<android.health.connect.datatypes.MedicalResource>,android.health.connect.HealthConnectException>)(https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/UpsertMedicalResourceRequest> requests, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource>, https://developer.android.com/reference/android/health/connect/HealthConnectException> callback) ` Inserts or updates a list of `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s into the HealthConnect database using `https://developer.android.com/reference/android/health/connect/UpsertMedicalResourceRequest`. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Constants

### ACTION_MANAGE_HEALTH_PERMISSIONS

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final String ACTION_MANAGE_HEALTH_PERMISSIONS
```

Activity action: Launch UI to manage (e.g. grant/revoke) health permissions.

Shows a list of apps which request at least one permission of the Health permission group.

Input: `https://developer.android.com/reference/android/content/Intent#EXTRA_PACKAGE_NAME` string extra with the name of the app requesting the action. Optional: Adding package name extras launches a UI to manager (e.g. grant/revoke) for this app.

<br />

Constant Value: "android.health.connect.action.MANAGE_HEALTH_PERMISSIONS"

### ACTION_REQUEST_EXERCISE_ROUTE

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final String ACTION_REQUEST_EXERCISE_ROUTE
```

Activity action: Launch UI to share the route associated with an exercise session.

Input: caller must provide \`String\` extra EXTRA_SESSION_ID

Result will be delivered via \[Activity.onActivityResult\] with \`ExerciseRoute\` EXTRA_EXERCISE_ROUTE.

<br />

Constant Value: "android.health.connect.action.REQUEST_EXERCISE_ROUTE"

### ACTION_SHOW_ONBOARDING

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)  
Also in [U Extensions 19](https://developer.android.com/sdkExtensions)

```
public static final String ACTION_SHOW_ONBOARDING
```

Activity action: Launch activity exported by client application that handles onboarding to Health Connect.

Health Connect will invoke this intent whenever the user attempts to connect an app that has exported an activity that responds to this intent. The launched activity is responsible for making permission requests and any other prerequisites for connecting to Health Connect.

Applications exporting an activity that is launched by this intent must also guard it with `https://developer.android.com/reference/android/health/connect/HealthPermissions#START_ONBOARDING` so that only the system can launch it.

<br />

Constant Value: "android.health.connect.action.SHOW_ONBOARDING"

### CATEGORY_HEALTH_PERMISSIONS

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final String CATEGORY_HEALTH_PERMISSIONS
```

Used in conjunction with `https://developer.android.com/reference/android/content/Intent#ACTION_VIEW_PERMISSION_USAGE` to launch UI to show an app\\u2019s health permission rationale/data policy.

**Note:** Used by apps to define an intent filter in conjunction with `https://developer.android.com/reference/android/content/Intent#ACTION_VIEW_PERMISSION_USAGE` that the HC UI can link out to.

<br />

Constant Value: "android.intent.category.HEALTH_PERMISSIONS"

### EXTRA_EXERCISE_ROUTE

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final String EXTRA_EXERCISE_ROUTE
```

An exercise route requested via `https://developer.android.com/reference/android/health/connect/HealthConnectManager#ACTION_REQUEST_EXERCISE_ROUTE`.

This is returned for a successful request to access a route associated with an exercise session.

<br />

Constant Value: "android.health.connect.extra.EXERCISE_ROUTE"

### EXTRA_SESSION_ID

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final String EXTRA_SESSION_ID
```

A string ID of a session to be used with `https://developer.android.com/reference/android/health/connect/HealthConnectManager#ACTION_REQUEST_EXERCISE_ROUTE`.

This is used to specify route of which exercise session we want to request.

<br />

Constant Value: "android.health.connect.extra.SESSION_ID"

## Public methods

### aggregate

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public void aggregate (AggregateRecordsRequest<T> request, 
                Executor executor, 
                OutcomeReceiver<AggregateRecordsResponse<T>, HealthConnectException> callback)
```

Get aggregations corresponding to `request`.

<br />

| Parameters ||
|---|---|
| `request` | `AggregateRecordsRequest`: request for different aggregation. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/health/connect/AggregateRecordsResponse#get(android.health.connect.datatypes.AggregationType<T>)`

### aggregateGroupByDuration

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public void aggregateGroupByDuration (AggregateRecordsRequest<T> request, 
                Duration duration, 
                Executor executor, 
                OutcomeReceiver<List<AggregateRecordsGroupedByDurationResponse<T>>, HealthConnectException> callback)
```

Get aggregations corresponding to `request`. Use this API if results are to be grouped by concrete intervals of time, for example 5 Hrs, 10 Hrs etc.

<br />

| Parameters ||
|---|---|
| `request` | `AggregateRecordsRequest`: request for different aggregation. This value cannot be `null`. <br /> |
| `duration` | `Duration`: Duration on which to group by results. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/health/connect/HealthConnectManager#aggregateGroupByPeriod(android.health.connect.AggregateRecordsRequest<T>,%20java.time.Period,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.util.List<android.health.connect.AggregateRecordsGroupedByPeriodResponse<T>>,android.health.connect.HealthConnectException>)`

### aggregateGroupByPeriod

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public void aggregateGroupByPeriod (AggregateRecordsRequest<T> request, 
                Period period, 
                Executor executor, 
                OutcomeReceiver<List<AggregateRecordsGroupedByPeriodResponse<T>>, HealthConnectException> callback)
```

Get aggregations corresponding to `request`. Use this API if results are to be grouped by number of days. This API handles changes in `https://developer.android.com/reference/java/time/ZoneOffset` when computing the data on a per-day basis.

<br />

| Parameters ||
|---|---|
| `request` | `AggregateRecordsRequest`: Request for different aggregation. This value cannot be `null`. <br /> |
| `period` | `Period`: Period on which to group by results. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/health/connect/AggregateRecordsGroupedByPeriodResponse#get(android.health.connect.datatypes.AggregationType<T>)`
- `https://developer.android.com/reference/android/health/connect/HealthConnectManager#aggregateGroupByDuration(android.health.connect.AggregateRecordsRequest<T>,%20java.time.Duration,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.util.List<android.health.connect.AggregateRecordsGroupedByDurationResponse<T>>,android.health.connect.HealthConnectException>)`

### createMatchmakingIntent

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 21](https://developer.android.com/sdkExtensions)

```
public Intent createMatchmakingIntent (MatchmakingRequest request)
```

Creates an `https://developer.android.com/reference/android/content/Intent` 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/android/health/connect/datatypes/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 `https://developer.android.com/reference/android/health/connect/datatypes/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.

**How to launch this Intent** This intent must be launched using the `https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher.html` with an appropriate contract (e.g., `https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContracts.StartActivityForResult.html`), or the `https://developer.android.com/reference/android/app/Activity#startActivityForResult(android.content.Intent,%20int)` API. It is not designed to be used with a `https://developer.android.com/reference/android/app/Activity#startActivity(android.content.Intent)` call. The launched activity may return a result code (e.g., `https://developer.android.com/reference/android/app/Activity#RESULT_OK` or `https://developer.android.com/reference/android/app/Activity#RESULT_CANCELED`) indicating the user's interaction with the flow:

- `https://developer.android.com/reference/android/app/Activity#RESULT_OK`: The user has successfully granted permissions to at least one application.
- `https://developer.android.com/reference/android/app/Activity#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#RESULT_CANCELED` can also occur if the intent was launched in a discouraged way when no matching apps are available. This can be avoided by ensuring `https://developer.android.com/reference/android/health/connect/HealthConnectManager#isMatchmakingPossible(android.health.connect.MatchmakingRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.MatchmakingResponse,android.health.connect.HealthConnectException>)` 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 `recordTypes`, and for the relevant included/excluded data sources:

- **If `recordTypes` is not empty:** The launched screen will focus on data sources capable of writing data for at least one of the specified health `recordTypes`. 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 considered ignored.
- **If `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 `includedDataSources` is not empty:** Only data sources whose package names are present in this set are considered for matchmaking. 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, but should identify available devices via `https://developer.android.com/reference/android/health/connect/HealthConnectManager#getDeviceDataSources(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.GetDeviceDataSourcesResponse,android.health.connect.HealthConnectException>)`.
- **If `excludedDataSources` is not empty:** Data sources whose package names are present in this set are excluded from matchmaking. As with inclusion, app data sources must be visible to the calling app, while device data sources do not require manifest declaration.
- **If both are empty:** All compatible data sources are considered.

Note: `includedDataSources` and `excludedDataSources` cannot both be non-empty at the same time.

<br />

| Parameters ||
|---|---|
| `request` | `MatchmakingRequest`: A `https://developer.android.com/reference/android/health/connect/MatchmakingRequest` that contains: - A non-null set of `https://developer.android.com/reference/android/health/connect/datatypes/Record` classes. If non-empty, the flow focuses on these specific types. If empty, the flow focuses on types for which the calling package has permission to read. - A non-null set of `https://developer.android.com/reference/android/health/connect/datatypes/DataOrigin` to include in matchmaking. If non-empty, only specified data origins are considered. App data origins must be visible to the calling app (declared in `<queries>`). Device data origins (from `https://developer.android.com/reference/android/health/connect/HealthConnectManager#getDeviceDataSources(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.GetDeviceDataSourcesResponse,android.health.connect.HealthConnectException>)`) do not require manifest declaration. - A non-null set of `https://developer.android.com/reference/android/health/connect/datatypes/DataOrigin` to exclude from matchmaking. If non-empty, specified data origins are EXCLUDED. App data origins must be visible to the calling app. Device data origins do not require manifest declaration. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/Intent` | An `https://developer.android.com/reference/android/content/Intent` configured to show the flow for discovering and managing write permissions for matching data origins. This intent must be launched using `https://developer.android.com/reference/android/app/Activity#startActivityForResult(android.content.Intent,%20int)`. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/`

### createMedicalDataSource

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 16](https://developer.android.com/sdkExtensions)

```
public void createMedicalDataSource (CreateMedicalDataSourceRequest request, 
                Executor executor, 
                OutcomeReceiver<MedicalDataSource, HealthConnectException> callback)
```

Creates a `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource` in HealthConnect based on the `https://developer.android.com/reference/android/health/connect/CreateMedicalDataSourceRequest` request values.

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

A `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource` needs to be created before any `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s for that source can be inserted. Separate `https://developer.android.com/reference/android/health/connect/datatypes/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/android/health/connect/CreateMedicalDataSourceRequest.Builder#setDisplayName(java.lang.String)` must be unique per app, and `https://developer.android.com/reference/android/health/connect/CreateMedicalDataSourceRequest.Builder#setFhirVersion(android.health.connect.datatypes.FhirVersion)` FHIR version} must be a version supported by Health Connect, as documented on the `https://developer.android.com/reference/android/health/connect/datatypes/FhirVersion`. See `https://developer.android.com/reference/android/health/connect/CreateMedicalDataSourceRequest.Builder#setFhirBaseUri(android.net.Uri)` for more details on the FHIR base URI.   

Requires `https://developer.android.com/reference/android/health/connect/HealthPermissions#WRITE_MEDICAL_DATA`

<br />

| Parameters ||
|---|---|
| `request` | `CreateMedicalDataSourceRequest`: Creation request. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `request` contains a FHIR base URI or display name exceeding the character limits, or an unsupported FHIR version. |

### deleteMedicalDataSourceWithData

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 16](https://developer.android.com/sdkExtensions)

```
public void deleteMedicalDataSourceWithData (String id, 
                Executor executor, 
                OutcomeReceiver<Void, HealthConnectException> callback)
```

Deletes a `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource` and all data linked to it.

If the provided data source `id` is either invalid, or does not exist, or owned by another apps, the caller will receive an exception with code `https://developer.android.com/reference/android/health/connect/HealthConnectException#ERROR_INVALID_ARGUMENT` via `callback.onError()`.

Regarding permissions:

- Only apps with the system permission can delete data written by apps other than themselves.
- Deletes are permitted in the foreground or background.

.   
Requires `https://developer.android.com/reference/android/health/connect/HealthPermissions#WRITE_MEDICAL_DATA` or android.health.connect.HealthPermissions.MANAGE_HEALTH_DATA_PERMISSION

<br />

<br />

| Parameters ||
|---|---|
| `id` | `String`: The id of the data source to delete. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

### deleteMedicalResources

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 16](https://developer.android.com/sdkExtensions)

```
public void deleteMedicalResources (List<MedicalResourceId> ids, 
                Executor executor, 
                OutcomeReceiver<Void, HealthConnectException> callback)
```

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

- If any ID in `ids` is invalid, the API will throw an `https://developer.android.com/reference/java/lang/IllegalArgumentException`, and nothing will be deleted.
- If any ID in `ids` does not exist, that ID will be ignored, while deletion on other IDs will be performed.

Regarding permissions:

- Only apps with the system permission can delete data written by apps other than themselves.
- Deletes are permitted in the foreground or background.

.   
Requires `https://developer.android.com/reference/android/health/connect/HealthPermissions#WRITE_MEDICAL_DATA` or android.health.connect.HealthPermissions.MANAGE_HEALTH_DATA_PERMISSION

<br />

<br />

| Parameters ||
|---|---|
| `ids` | `List`: The ids to delete. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

### deleteMedicalResources

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 16](https://developer.android.com/sdkExtensions)

```
public void deleteMedicalResources (DeleteMedicalResourcesRequest request, 
                Executor executor, 
                OutcomeReceiver<Void, HealthConnectException> callback)
```

Deletes `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s based on given filters in `https://developer.android.com/reference/android/health/connect/DeleteMedicalResourcesRequest`.

Regarding permissions:

- Only apps with the system permission can delete data written by apps other than themselves.
- Deletes are permitted in the foreground or background.

.   
Requires `https://developer.android.com/reference/android/health/connect/HealthPermissions#WRITE_MEDICAL_DATA` or android.health.connect.HealthPermissions.MANAGE_HEALTH_DATA_PERMISSION

<br />

<br />

| Parameters ||
|---|---|
| `request` | `DeleteMedicalResourcesRequest`: The delete request. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `request` contains unsupported medical resource types or invalid `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource` IDs. |

### deleteRecords

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public void deleteRecords (List<RecordIdFilter> recordIds, 
                Executor executor, 
                OutcomeReceiver<Void, HealthConnectException> callback)
```

Deletes records based on `https://developer.android.com/reference/android/health/connect/RecordIdFilter`.

Deletions are performed in a transaction i.e. either all will be deleted or none

<br />

| Parameters ||
|---|---|
| `recordIds` | `List`: recordIds on which to perform delete operation. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `recordIds is empty` |

### deleteRecords

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public void deleteRecords (Class<? extends Record> recordType, 
                TimeRangeFilter timeRangeFilter, 
                Executor executor, 
                OutcomeReceiver<Void, HealthConnectException> callback)
```

Deletes records based on the `https://developer.android.com/reference/android/health/connect/TimeRangeFilter`.

Deletions are performed in a transaction i.e. either all will be deleted or none

<br />

| Parameters ||
|---|---|
| `recordType` | `Class`: recordType to perform delete operation on. This value cannot be `null`. <br /> |
| `timeRangeFilter` | `TimeRangeFilter`: time filter based on which to delete the records. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

### getChangeLogToken

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public void getChangeLogToken (ChangeLogTokenRequest request, 
                Executor executor, 
                OutcomeReceiver<ChangeLogTokenResponse, HealthConnectException> callback)
```

Get token for {HealthConnectManager#getChangeLogs}. Changelogs requested corresponding to this token will be post the time this token was generated by the system all items that match the given filters.

If the app doesn't have the necessary permissions to read data of any type requested here, the request will throw an exception.

Tokens from this request are to be passed to {HealthConnectManager#getChangeLogs}

<br />

| Parameters ||
|---|---|
| `request` | `ChangeLogTokenRequest`: A request to get changelog token. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

### getChangeLogs

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public void getChangeLogs (ChangeLogsRequest changeLogsRequest, 
                Executor executor, 
                OutcomeReceiver<ChangeLogsResponse, HealthConnectException> callback)
```

Get change logs post the time when `token` was generated.

<br />

| Parameters ||
|---|---|
| `changeLogsRequest` | `ChangeLogsRequest`: The token from `https://developer.android.com/reference/android/health/connect/HealthConnectManager#getChangeLogToken(android.health.connect.changelog.ChangeLogTokenRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.changelog.ChangeLogTokenResponse,android.health.connect.HealthConnectException>)`. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/health/connect/HealthConnectManager#getChangeLogToken(android.health.connect.changelog.ChangeLogTokenRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.changelog.ChangeLogTokenResponse,android.health.connect.HealthConnectException>)`

### getCurrentDeviceDataSource

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 22](https://developer.android.com/sdkExtensions)

```
public void getCurrentDeviceDataSource (Executor executor, 
                OutcomeReceiver<DeviceDataSource, HealthConnectException> callback)
```

Retrieves the `https://developer.android.com/reference/android/health/connect/DeviceDataSource` for the current device.

The caller must hold at least one Health Connect read permission in order to call this method.

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

### getDeviceDataSourceCapabilities

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 22](https://developer.android.com/sdkExtensions)

```
public void getDeviceDataSourceCapabilities (Executor executor, 
                OutcomeReceiver<DeviceDataSourceCapabilities, HealthConnectException> callback)
```

Returns a set of record type classes that device data sources are capable of providing.

Use this method to avoid making unnecessary permission requests when reading device data in case the data type is not provided by any device data sources.

This will filter out any permission sensitive data types the caller does not hold read permissions for. Data types belonging to `https://developer.android.com/reference/android/health/connect/HealthConnectManager#getPermissionSensitiveDeviceDataSourceCapabilities()` are excluded from the response unless the caller holds read permissions for those data types.

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

### getDeviceDataSources

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 22](https://developer.android.com/sdkExtensions)

```
public void getDeviceDataSources (Executor executor, 
                OutcomeReceiver<GetDeviceDataSourcesResponse, HealthConnectException> callback)
```

Retrieves the list of all `https://developer.android.com/reference/android/health/connect/DeviceDataSource`s.

The returned list includes all devices that have been advertised by device data providers, filtered based on the caller's permissions. A device is included if the caller holds the READ permission for at least one of the data types supported by the device. Other data types supported by the device that the caller does not have permission for will nonetheless be included.

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

### getMedicalDataSources

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 16](https://developer.android.com/sdkExtensions)

```
public void getMedicalDataSources (List<String> ids, 
                Executor executor, 
                OutcomeReceiver<List<MedicalDataSource>, HealthConnectException> callback)
```

Returns `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource`s for the provided list of IDs.

The number and order of medical data sources returned by this API is not guaranteed. The number will depend on the factors below:

- If an empty list of `ids` is provided, an empty list will be returned.
- If any ID in `ids` is invalid, the caller will receive an exception with code `https://developer.android.com/reference/android/health/connect/HealthConnectException#ERROR_INVALID_ARGUMENT` via `callback.onError()`.
- If any ID in `ids` does not exist, no data source will be returned for that ID.
- 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 linked to that data source. Being permitted to get data sources is dependent on the following logic, in priority order, earlier statements take precedence.

1. A caller with the system permission can get any data source in the foreground or background.
2. A caller without any read or write permissions for health data will not be able to get any medical data sources and receive an exception with code `https://developer.android.com/reference/android/health/connect/HealthConnectException#ERROR_SECURITY` via `callback.onError()`, even for data sources the caller has created.
3. Callers can get data sources they have created, whether this method is called in the foreground or background. Note this only applies if the caller has at least one read or write permission for health data.
4. For any given data source, a caller can get that data source in the foreground if the caller has permission to read any of the data linked to that data source. For clarity, the does not allow it to get an empty data source.
5. For any given data source, a caller can get that data source in the background if it has both permission to read any of the data linked to that data source, and `https://developer.android.com/reference/android/health/connect/HealthPermissions#READ_HEALTH_DATA_IN_BACKGROUND`.
6. In all other cases the caller is not permitted to get the given data source and it will not be returned.

<br />

<br />

| Parameters ||
|---|---|
| `ids` | `List`: Identifiers for data sources to get. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the size of `ids` is more than 5000. |

### getMedicalDataSources

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 16](https://developer.android.com/sdkExtensions)

```
public void getMedicalDataSources (GetMedicalDataSourcesRequest request, 
                Executor executor, 
                OutcomeReceiver<List<MedicalDataSource>, HealthConnectException> callback)
```

Returns the requested `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource`s.

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

- If an empty `https://developer.android.com/reference/android/health/connect/GetMedicalDataSourcesRequest#getPackageNames()` is passed, all permitted data sources from all apps will be returned. See below.
- If any package name in the `https://developer.android.com/reference/android/health/connect/GetMedicalDataSourcesRequest#getPackageNames()` is invalid, the API will throw an `https://developer.android.com/reference/java/lang/IllegalArgumentException`.
- If a non-empty `https://developer.android.com/reference/android/health/connect/GetMedicalDataSourcesRequest#getPackageNames()` is specified in the request, then only the permitted data sources created by those packages 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 linked to that data source. Being permitted to get data sources is dependent on the following logic, in priority order, earlier statements take precedence.

1. A caller with the system permission can get any data source in the foreground or background.
2. A caller without any read or write permissions for health data will not be able to get any medical data sources and receive an exception with code `https://developer.android.com/reference/android/health/connect/HealthConnectException#ERROR_SECURITY` via `callback.onError()`, even for data sources the caller has created.
3. Callers can get data sources they have created, whether this method is called in the foreground or background. Note this only applies if the caller has at least one read or write permission for health data.
4. For any given data source, a caller can get that data source in the foreground if the caller has permission to read any of the data linked to that data source. For clarity, the does not allow it to get an empty data source.
5. For any given data source, a caller can get that data source in the background if it has both permission to read any of the data linked to that data source, and `https://developer.android.com/reference/android/health/connect/HealthPermissions#READ_HEALTH_DATA_IN_BACKGROUND`.
6. In all other cases the caller is not permitted to get the given data source and it will not be returned.

<br />

<br />

| Parameters ||
|---|---|
| `request` | `GetMedicalDataSourcesRequest`: the request for which data sources to return. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `request` contains invalid package names. |

### getPermissionSensitiveDeviceDataSourceCapabilities

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 22](https://developer.android.com/sdkExtensions)

```
public static Set<Class<? extends Record>> getPermissionSensitiveDeviceDataSourceCapabilities ()
```

Returns the set of data types which are excluded from the output of #getDeviceDataSourceCapabilities unless the caller holds the read permission for those data types.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/Class<? extends https://developer.android.com/reference/android/health/connect/datatypes/Record>>` | This value cannot be `null`. <br /> |

### insertRecords

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public void insertRecords (List<Record> records, 
                Executor executor, 
                OutcomeReceiver<InsertRecordsResponse, HealthConnectException> callback)
```

Inserts `records` into the HealthConnect database. The records returned in `https://developer.android.com/reference/android/health/connect/InsertRecordsResponse` contains the unique IDs of the input records. The values are in same order as `records`. In case of an error or a permission failure the HealthConnect service, `https://developer.android.com/reference/android/os/OutcomeReceiver#onError(E)` will be invoked with a `https://developer.android.com/reference/android/health/connect/HealthConnectException`.

<br />

| Parameters ||
|---|---|
| `records` | `List`: list of records to be inserted. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | for internal errors |

### isMatchmakingPossible

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 21](https://developer.android.com/sdkExtensions)

```
public void isMatchmakingPossible (MatchmakingRequest request, 
                Executor executor, 
                OutcomeReceiver<MatchmakingResponse, HealthConnectException> callback)
```

Checks if launching the intent returned by `https://developer.android.com/reference/android/health/connect/HealthConnectManager#createMatchmakingIntent(android.health.connect.MatchmakingRequest)` with the same arguments will result in showing at least one matching data source.

- Returns `true` if the flow launched by the `https://developer.android.com/reference/android/content/Intent` from `https://developer.android.com/reference/android/health/connect/HealthConnectManager#createMatchmakingIntent(android.health.connect.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#RESULT_CANCELED` because there are no relevant data sources to show.

<br />

<br />

| Parameters ||
|---|---|
| `request` | `MatchmakingRequest`: A non-null `https://developer.android.com/reference/android/health/connect/MatchmakingRequest` that contains a set of `https://developer.android.com/reference/android/health/connect/datatypes/Record` classes. See description at `https://developer.android.com/reference/android/health/connect/HealthConnectManager#createMatchmakingIntent(android.health.connect.MatchmakingRequest)`. <br /> |
| `executor` | `Executor`: A non-null `https://developer.android.com/reference/java/util/concurrent/Executor` on which the `callback` will be invoked. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: A non-null `https://developer.android.com/reference/android/os/OutcomeReceiver` to receive the result. The `onResult` method will be called with a boolean indicating if there are matching writing data sources to show. The `onError` method will be called if an error occurs. <br /> |

**See also:**

- `https://developer.android.com/reference/android/health/connect/HealthConnectManager#createMatchmakingIntent(android.health.connect.MatchmakingRequest)`

### readMedicalResources

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 16](https://developer.android.com/sdkExtensions)

```
public void readMedicalResources (List<MedicalResourceId> ids, 
                Executor executor, 
                OutcomeReceiver<List<MedicalResource>, HealthConnectException> callback)
```

Reads `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s based on a list of `https://developer.android.com/reference/android/health/connect/MedicalResourceId`s.

The number and order of medical resources returned by this API is not guaranteed. The number will depend on the factors below:

- If an empty list of `ids` is provided, an empty list will be returned.
- If the size of `ids` is more than 5000, the API will throw an `https://developer.android.com/reference/java/lang/IllegalArgumentException`.
- If any ID in `ids` is invalid, the API will throw an `https://developer.android.com/reference/java/lang/IllegalArgumentException`.
- If any ID in `ids` does not exist, no medical resource will be returned for that ID.
- Callers will only get medical resources they are permitted to get. See below.

Being permitted to read medical resources is dependent on the following logic, in priority order, earlier statements take precedence.

1. A caller with the system permission can get any medical resources in the foreground or background.
2. A caller without any read or write permissions for health data will not be able to get any medical resources and receive an exception with code `https://developer.android.com/reference/android/health/connect/HealthConnectException#ERROR_SECURITY` via `callback.onError()`, even for medical resources the caller has created.
3. Callers can get medical resources they have created, whether this method is called in the foreground or background. Note this only applies if the caller has at least one read or write permission for health data.
4. For any given medical resource, a caller can get that medical resource in the foreground if the caller has the corresponding read permission, or in the background if it also has `https://developer.android.com/reference/android/health/connect/HealthPermissions#READ_HEALTH_DATA_IN_BACKGROUND`.
5. In all other cases the caller is not permitted to get the given medical resource and it will not be returned.

Each returned `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource` has passed the Health Connect FHIR validation checks at write time, but 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 checks on the data.

<br />

| Parameters ||
|---|---|
| `ids` | `List`: Identifiers on which to perform read operation. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the size of `ids` is more than 5000 or if any id is invalid. |

### readMedicalResources

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 16](https://developer.android.com/sdkExtensions)

```
public void readMedicalResources (ReadMedicalResourcesRequest request, 
                Executor executor, 
                OutcomeReceiver<ReadMedicalResourcesResponse, HealthConnectException> callback)
```

Reads `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s based on `https://developer.android.com/reference/android/health/connect/ReadMedicalResourcesInitialRequest` or `https://developer.android.com/reference/android/health/connect/ReadMedicalResourcesPageRequest`.

Being permitted to read medical resources is dependent on the following logic, in priority order, earlier statements take precedence.

1. A caller with the system permission can get any medical resources in the foreground or background.
2. A caller without any read or write permissions for health data will not be able to get any medical resources and receive an exception with code `https://developer.android.com/reference/android/health/connect/HealthConnectException#ERROR_SECURITY` via `callback.onError()`, even for medical resources the caller has created.
3. Callers can get medical resources they have created, whether this method is called in the foreground or background. Note this only applies if the caller has at least one read or write permission for health data.
4. For any given medical resource, a caller can get that medical resource in the foreground if the caller has the corresponding read permission, or in the background if it also has `https://developer.android.com/reference/android/health/connect/HealthPermissions#READ_HEALTH_DATA_IN_BACKGROUND`.
5. In all other cases the caller is not permitted to get the given medical resource and it will not be returned.

<br />

<br />

| Parameters ||
|---|---|
| `request` | `ReadMedicalResourcesRequest`: The read request `https://developer.android.com/reference/android/health/connect/ReadMedicalResourcesInitialRequest` or `https://developer.android.com/reference/android/health/connect/ReadMedicalResourcesPageRequest`. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `request` has set page size to be less than 1 or more than 5000; or if contains unsupported medical resource type or invalid `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource` IDs when using `https://developer.android.com/reference/android/health/connect/ReadMedicalResourcesInitialRequest`. |

### readRecords

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public void readRecords (ReadRecordsRequest<T> request, 
                Executor executor, 
                OutcomeReceiver<ReadRecordsResponse<T>, HealthConnectException> callback)
```

API to read records based on `https://developer.android.com/reference/android/health/connect/ReadRecordsRequestUsingFilters` or `https://developer.android.com/reference/android/health/connect/ReadRecordsRequestUsingIds`

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

When an app with read permission allowed calls the API from background then it will be able to read only its own inserted records and will not get records inserted by other apps. This may be less than the total records present for the record type.

When an app with read permission allowed calls the API from foreground then it will be able to read all records for the record type.

App with only write permission but no read permission allowed will be able to read only its own inserted records both when in foreground or background.

An app without both read and write permissions will not be able to read any record and the API will throw Security Exception.

<br />

| Parameters ||
|---|---|
| `request` | `ReadRecordsRequest`: Read request based on `https://developer.android.com/reference/android/health/connect/ReadRecordsRequestUsingFilters` or `https://developer.android.com/reference/android/health/connect/ReadRecordsRequestUsingIds` This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if request page size set is more than 5000 in `https://developer.android.com/reference/android/health/connect/ReadRecordsRequestUsingFilters` |
| `https://developer.android.com/reference/java/lang/SecurityException` | if app without read or write permission tries to read. |

### updateRecords

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 7](https://developer.android.com/sdkExtensions)

```
public void updateRecords (List<Record> records, 
                Executor executor, 
                OutcomeReceiver<Void, HealthConnectException> callback)
```

Updates `records` into the HealthConnect database. In case of an error or a permission failure the HealthConnect service, `https://developer.android.com/reference/android/os/OutcomeReceiver#onError(E)` will be invoked with a `https://developer.android.com/reference/android/health/connect/HealthConnectException`.

In case the input record to be updated does not exist in the database or the caller is not the owner of the record then `https://developer.android.com/reference/android/health/connect/HealthConnectException#ERROR_INVALID_ARGUMENT` will be thrown.

<br />

| Parameters ||
|---|---|
| `records` | `List`: list of records to be updated. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if at least one of the records is missing both ClientRecordID and UUID. |

### upsertMedicalResources

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 16](https://developer.android.com/sdkExtensions)

```
public void upsertMedicalResources (List<UpsertMedicalResourceRequest> requests, 
                Executor executor, 
                OutcomeReceiver<List<MedicalResource>, HealthConnectException> callback)
```

Inserts or updates a list of `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s into the HealthConnect database using `https://developer.android.com/reference/android/health/connect/UpsertMedicalResourceRequest`.

For each `https://developer.android.com/reference/android/health/connect/UpsertMedicalResourceRequest`, one `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource` will be returned. The returned list of `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s will be in the same order as the `requests`.

Note that a `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource` needs to be created using `https://developer.android.com/reference/android/health/connect/HealthConnectManager#createMedicalDataSource(android.health.connect.CreateMedicalDataSourceRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.health.connect.datatypes.MedicalDataSource,android.health.connect.HealthConnectException>)` before any `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource`s can be upserted for this source.

Medical data is represented using the [Fast Healthcare Interoperability Resources (FHIR)](https://hl7.org/fhir/) standard. The FHIR resource provided in `https://developer.android.com/reference/android/health/connect/UpsertMedicalResourceRequest#getData()` is expected to be valid FHIR in JSON representation for the specified `https://developer.android.com/reference/android/health/connect/UpsertMedicalResourceRequest#getFhirVersion()` 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 are performed, but these checks may not cover all FHIR spec requirements and may change in future versions.

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/android/health/connect/UpsertMedicalResourceRequest` also has to meet the following requirements.

- The FHIR resource contains an "id" and "resourceType" field.
- The FHIR resource type is in our accepted list of resource types. See `https://developer.android.com/reference/android/health/connect/datatypes/FhirResource` for the accepted types.
- The FHIR resource does not contain any "contained" resources.
- The resource can be mapped to one of the READ_MEDICAL_DATA_ `https://developer.android.com/reference/android/health/connect/HealthPermissions` categories.
- The `https://developer.android.com/reference/android/health/connect/UpsertMedicalResourceRequest#getDataSourceId()` is valid.
- The `https://developer.android.com/reference/android/health/connect/UpsertMedicalResourceRequest#getFhirVersion()` matches the `https://developer.android.com/reference/android/health/connect/datatypes/FhirVersion` of the `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource`.

If any request contains invalid `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource` IDs, the API will throw an `https://developer.android.com/reference/java/lang/IllegalArgumentException`, and none of the `requests` will be upserted into the HealthConnect database.

If any request is deemed invalid for any other reasons, the caller will receive an exception with code `https://developer.android.com/reference/android/health/connect/HealthConnectException#ERROR_INVALID_ARGUMENT` via `callback.onError()`, and none of the `requests` will be upserted into the HealthConnect database.

If data for any `https://developer.android.com/reference/android/health/connect/UpsertMedicalResourceRequest` fails to be upserted, then no data from any `requests` will be upserted into the database.

The uniqueness of each request is calculated comparing the combination of `https://developer.android.com/reference/android/health/connect/UpsertMedicalResourceRequest#getDataSourceId()`, FHIR resource type and FHIR resource ID extracted from the provided `https://developer.android.com/reference/android/health/connect/UpsertMedicalResourceRequest#getData()`. If the above combination does not match with an existing one in Health Connect, then a new `https://developer.android.com/reference/android/health/connect/datatypes/MedicalResource` is inserted, otherwise the existing one is updated.   

Requires `https://developer.android.com/reference/android/health/connect/HealthPermissions#WRITE_MEDICAL_DATA`

<br />

| Parameters ||
|---|---|
| `requests` | `List`: List of upsert requests. This value cannot be `null`. <br /> |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: Callback to receive result of performing this operation. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if any `requests` contains invalid `https://developer.android.com/reference/android/health/connect/datatypes/MedicalDataSource` IDs. |