Added in API level 34

HealthConnectManager


open class HealthConnectManager
kotlin.Any
   ↳ android.health.connect.HealthConnectManager

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 Record object, which is the base class for all the other data types such as .

Summary

Constants
static String

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

static String

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

static String

Used in conjunction with android.content.Intent#ACTION_VIEW_PERMISSION_USAGE to launch UI to show an app’s health permission rationale/data policy.

static String

An exercise route requested via ACTION_REQUEST_EXERCISE_ROUTE.

static String

A string ID of a session to be used with ACTION_REQUEST_EXERCISE_ROUTE.

Public methods
open Unit

Get aggregations corresponding to request.

open Unit

Get aggregations corresponding to request.

open Unit

Get aggregations corresponding to request.

open Unit

Creates a MedicalDataSource in HealthConnect based on the CreateMedicalDataSourceRequest request values.

open Unit

Deletes a MedicalDataSource and all data linked to it.

open Unit

Deletes MedicalResources based on given filters in DeleteMedicalResourcesRequest.

open Unit

Deletes a list of MedicalResources by the provided list of MedicalResourceIds.

open Unit
deleteRecords(recordType: Class<out Record!>, timeRangeFilter: TimeRangeFilter, executor: Executor, callback: OutcomeReceiver<Void!, HealthConnectException!>)

Deletes records based on the TimeRangeFilter.

open Unit

Deletes records based on RecordIdFilter.

open Unit

Get token for {HealthConnectManager#getChangeLogs}.

open Unit

Get change logs post the time when token was generated.

open Unit

Returns the requested MedicalDataSources.

open Unit

Returns MedicalDataSources for the provided list of IDs.

open Unit

Inserts records into the HealthConnect database.

open Unit

Reads MedicalResources based on ReadMedicalResourcesInitialRequest or ReadMedicalResourcesPageRequest.

open Unit

Reads MedicalResources based on a list of MedicalResourceIds.

open Unit

API to read records based on ReadRecordsRequestUsingFilters or ReadRecordsRequestUsingIds

open Unit

Updates records into the HealthConnect database.

open Unit

Inserts or updates a list of MedicalResources into the HealthConnect database using UpsertMedicalResourceRequest.

Constants

ACTION_MANAGE_HEALTH_PERMISSIONS

Added in API level 34
static val ACTION_MANAGE_HEALTH_PERMISSIONS: String

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: 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.

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

ACTION_REQUEST_EXERCISE_ROUTE

Added in API level 34
static val ACTION_REQUEST_EXERCISE_ROUTE: String

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.

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

CATEGORY_HEALTH_PERMISSIONS

Added in API level 34
static val CATEGORY_HEALTH_PERMISSIONS: String

Used in conjunction with android.content.Intent#ACTION_VIEW_PERMISSION_USAGE to launch UI to show an app’s health permission rationale/data policy.

Note: Used by apps to define an intent filter in conjunction with android.content.Intent#ACTION_VIEW_PERMISSION_USAGE that the HC UI can link out to.

Value: "android.intent.category.HEALTH_PERMISSIONS"

EXTRA_EXERCISE_ROUTE

Added in API level 34
static val EXTRA_EXERCISE_ROUTE: String

An exercise route requested via ACTION_REQUEST_EXERCISE_ROUTE.

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

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

EXTRA_SESSION_ID

Added in API level 34
static val EXTRA_SESSION_ID: String

A string ID of a session to be used with ACTION_REQUEST_EXERCISE_ROUTE.

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

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

Public methods

aggregate

Added in API level 34
open fun <T : Any!> aggregate(
    request: AggregateRecordsRequest<T>,
    executor: Executor,
    callback: OutcomeReceiver<AggregateRecordsResponse<T>!, HealthConnectException!>
): Unit

Get aggregations corresponding to request.

Parameters
<T> Result type of the aggregation.

Note:

This type is embedded in the AggregationType as AggregationType are typed in nature.

Only AggregationTypes that are of same type T can be queried together

request AggregateRecordsRequest<T>: request for different aggregation. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<AggregateRecordsResponse<T>!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.

aggregateGroupByDuration

Added in API level 34
open fun <T : Any!> aggregateGroupByDuration(
    request: AggregateRecordsRequest<T>,
    duration: Duration,
    executor: Executor,
    callback: OutcomeReceiver<MutableList<AggregateRecordsGroupedByDurationResponse<T>!>!, HealthConnectException!>
): Unit

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.

Parameters
<T> Result type of the aggregation.

Note:

This type is embedded in the AggregationType as AggregationType are typed in nature.

Only AggregationTypes that are of same type T can be queried together

request AggregateRecordsRequest<T>: request for different aggregation. This value cannot be null.
duration Duration: Duration on which to group by results This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<MutableList<AggregateRecordsGroupedByDurationResponse<T>!>!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.

aggregateGroupByPeriod

Added in API level 34
open fun <T : Any!> aggregateGroupByPeriod(
    request: AggregateRecordsRequest<T>,
    period: Period,
    executor: Executor,
    callback: OutcomeReceiver<MutableList<AggregateRecordsGroupedByPeriodResponse<T>!>!, HealthConnectException!>
): Unit

Get aggregations corresponding to request. Use this API if results are to be grouped by number of days. This API handles changes in ZoneOffset when computing the data on a per-day basis.

Parameters
<T> Result type of the aggregation.

Note:

This type is embedded in the AggregationType as AggregationType are typed in nature.

Only AggregationTypes that are of same type T can be queried together

request AggregateRecordsRequest<T>: Request for different aggregation. This value cannot be null.
period Period: Period on which to group by results This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<MutableList<AggregateRecordsGroupedByPeriodResponse<T>!>!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.

createMedicalDataSource

open fun createMedicalDataSource(
    request: CreateMedicalDataSourceRequest,
    executor: Executor,
    callback: OutcomeReceiver<MedicalDataSource!, HealthConnectException!>
): Unit

Creates a MedicalDataSource in HealthConnect based on the CreateMedicalDataSourceRequest request values.

A MedicalDataSource needs to be created before any MedicalResources for that source can be inserted.

Medical data is represented using the Fast Healthcare Interoperability Resources (FHIR) standard.

The display name must be unique per app, and CreateMedicalDataSourceRequest.Builder.setFhirVersion FHIR version} must be a version supported by Health Connect, as documented on the FhirVersion.
Requires android.health.connect.HealthPermissions#WRITE_MEDICAL_DATA

Parameters
request CreateMedicalDataSourceRequest: Creation request. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<MedicalDataSource!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if request contains a FHIR base URI or display name exceeding the character limits, or an unsupported FHIR version.

deleteMedicalDataSourceWithData

open fun deleteMedicalDataSourceWithData(
    id: String,
    executor: Executor,
    callback: OutcomeReceiver<Void!, HealthConnectException!>
): Unit

Deletes a 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 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 android.health.connect.HealthPermissions#WRITE_MEDICAL_DATA or android.health.connect.HealthPermissions.MANAGE_HEALTH_DATA_PERMISSION
Parameters
id String: The id of the data source to delete. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<Void!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.

deleteMedicalResources

open fun deleteMedicalResources(
    request: DeleteMedicalResourcesRequest,
    executor: Executor,
    callback: OutcomeReceiver<Void!, HealthConnectException!>
): Unit

Deletes MedicalResources based on given filters in 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 android.health.connect.HealthPermissions#WRITE_MEDICAL_DATA or android.health.connect.HealthPermissions.MANAGE_HEALTH_DATA_PERMISSION
Parameters
request DeleteMedicalResourcesRequest: The delete request. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<Void!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if request contains unsupported medical resource types or invalid MedicalDataSource IDs.

deleteMedicalResources

open fun deleteMedicalResources(
    ids: MutableList<MedicalResourceId!>,
    executor: Executor,
    callback: OutcomeReceiver<Void!, HealthConnectException!>
): Unit

Deletes a list of MedicalResources by the provided list of MedicalResourceIds.

  • If any ID in ids is invalid, the API will throw an 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 android.health.connect.HealthPermissions#WRITE_MEDICAL_DATA or android.health.connect.HealthPermissions.MANAGE_HEALTH_DATA_PERMISSION
Parameters
ids MutableList<MedicalResourceId!>: The ids to delete. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<Void!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.

deleteRecords

Added in API level 34
open fun deleteRecords(
    recordType: Class<out Record!>,
    timeRangeFilter: TimeRangeFilter,
    executor: Executor,
    callback: OutcomeReceiver<Void!, HealthConnectException!>
): Unit

Deletes records based on the TimeRangeFilter.

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

Parameters
recordType Class<out Record!>: recordType to perform delete operation on. This value cannot be null.
timeRangeFilter TimeRangeFilter: time filter based on which to delete the records. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<Void!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.

deleteRecords

Added in API level 34
open fun deleteRecords(
    recordIds: MutableList<RecordIdFilter!>,
    executor: Executor,
    callback: OutcomeReceiver<Void!, HealthConnectException!>
): Unit

Deletes records based on RecordIdFilter.

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

Parameters
recordIds MutableList<RecordIdFilter!>: recordIds on which to perform delete operation. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<Void!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if recordIds is empty

getChangeLogToken

Added in API level 34
open fun getChangeLogToken(
    request: ChangeLogTokenRequest,
    executor: Executor,
    callback: OutcomeReceiver<ChangeLogTokenResponse!, HealthConnectException!>
): Unit

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.

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

Parameters
request ChangeLogTokenRequest: A request to get changelog token This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<ChangeLogTokenResponse!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.

getChangeLogs

Added in API level 34
open fun getChangeLogs(
    changeLogsRequest: ChangeLogsRequest,
    executor: Executor,
    callback: OutcomeReceiver<ChangeLogsResponse!, HealthConnectException!>
): Unit

Get change logs post the time when token was generated.

Parameters
changeLogsRequest ChangeLogsRequest: The token from HealthConnectManager.getChangeLogToken. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<ChangeLogsResponse!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.

getMedicalDataSources

open fun getMedicalDataSources(
    request: GetMedicalDataSourcesRequest,
    executor: Executor,
    callback: OutcomeReceiver<MutableList<MedicalDataSource!>!, HealthConnectException!>
): Unit

Returns the requested MedicalDataSources.

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

  • If an empty names is passed, all permitted data sources from all apps will be returned. See below.
  • If any package name in the of package names is invalid, the API will throw an IllegalArgumentException.
  • If a non-empty names 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 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 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.
Parameters
request GetMedicalDataSourcesRequest: the request for which data sources to return. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<MutableList<MedicalDataSource!>!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if request contains invalid package names.

getMedicalDataSources

open fun getMedicalDataSources(
    ids: MutableList<String!>,
    executor: Executor,
    callback: OutcomeReceiver<MutableList<MedicalDataSource!>!, HealthConnectException!>
): Unit

Returns MedicalDataSources for the provided list of IDs.

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

  • 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 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 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 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.
Parameters
ids MutableList<String!>: Identifiers for data sources to get. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<MutableList<MedicalDataSource!>!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.

insertRecords

Added in API level 34
open fun insertRecords(
    records: MutableList<Record!>,
    executor: Executor,
    callback: OutcomeReceiver<InsertRecordsResponse!, HealthConnectException!>
): Unit

Inserts records into the HealthConnect database. The records returned in 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, OutcomeReceiver.onError will be invoked with a HealthConnectException.

Parameters
records MutableList<Record!>: list of records to be inserted. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<InsertRecordsResponse!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.
Exceptions
java.lang.RuntimeException for internal errors

readMedicalResources

open fun readMedicalResources(
    request: ReadMedicalResourcesRequest,
    executor: Executor,
    callback: OutcomeReceiver<ReadMedicalResourcesResponse!, HealthConnectException!>
): Unit

Reads MedicalResources based on ReadMedicalResourcesInitialRequest or 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 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 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.
Parameters
request ReadMedicalResourcesRequest: The read request ReadMedicalResourcesInitialRequest or ReadMedicalResourcesPageRequest. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<ReadMedicalResourcesResponse!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.
Exceptions
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 MedicalDataSource IDs when using ReadMedicalResourcesInitialRequest.

readMedicalResources

open fun readMedicalResources(
    ids: MutableList<MedicalResourceId!>,
    executor: Executor,
    callback: OutcomeReceiver<MutableList<MedicalResource!>!, HealthConnectException!>
): Unit

Reads MedicalResources based on a list of MedicalResourceIds.

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

  • 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 IllegalArgumentException.
  • If any ID in ids is invalid, the API will throw an 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 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 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 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. If required, clients should perform their own checks on the data.

Parameters
ids MutableList<MedicalResourceId!>: Identifiers on which to perform read operation. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<MutableList<MedicalResource!>!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if the size of ids is more than 5000 or if any id is invalid.

readRecords

Added in API level 34
open fun <T : Record!> readRecords(
    request: ReadRecordsRequest<T>,
    executor: Executor,
    callback: OutcomeReceiver<ReadRecordsResponse<T>!, HealthConnectException!>
): Unit

API to read records based on ReadRecordsRequestUsingFilters or 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.

Parameters
request ReadRecordsRequest<T>: Read request based on ReadRecordsRequestUsingFilters or ReadRecordsRequestUsingIds This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null.
callback OutcomeReceiver<ReadRecordsResponse<T>!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if request page size set is more than 5000 in ReadRecordsRequestUsingFilters
java.lang.SecurityException if app without read or write permission tries to read.

updateRecords

Added in API level 34
open fun updateRecords(
    records: MutableList<Record!>,
    executor: Executor,
    callback: OutcomeReceiver<Void!, HealthConnectException!>
): Unit

Updates records into the HealthConnect database. In case of an error or a permission failure the HealthConnect service, OutcomeReceiver.onError will be invoked with a 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 HealthConnectException.ERROR_INVALID_ARGUMENT will be thrown.

Parameters
records MutableList<Record!>: list of records to be updated. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<Void!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if at least one of the records is missing both ClientRecordID and UUID.

upsertMedicalResources

open fun upsertMedicalResources(
    requests: MutableList<UpsertMedicalResourceRequest!>,
    executor: Executor,
    callback: OutcomeReceiver<MutableList<MedicalResource!>!, HealthConnectException!>
): Unit

Inserts or updates a list of MedicalResources into the HealthConnect database using UpsertMedicalResourceRequest.

For each UpsertMedicalResourceRequest, one MedicalResource will be returned. The returned list of MedicalResources will be in the same order as the requests.

Medical data is represented using the Fast Healthcare Interoperability Resources (FHIR) standard. The FHIR resource provided in android.health.connect.UpsertMedicalResourceRequest#getData() is expected to be valid FHIR in JSON representation for the specified UpsertMedicalResourceRequest.getFhirVersion() according to the FHIR spec.

Each UpsertMedicalResourceRequest also has to meet the following requirements.

If any request contains invalid MedicalDataSource IDs, the API will throw an 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 HealthConnectException.ERROR_INVALID_ARGUMENT via callback.onError(), and none of the requests will be upserted into the HealthConnect database.

If data for any 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 data source id, FHIR resource type and FHIR resource ID extracted from the provided data. If the above combination does not match with an existing one in Health Connect, then a new MedicalResource is inserted, otherwise the existing one is updated.
Requires android.health.connect.HealthPermissions#WRITE_MEDICAL_DATA

Parameters
requests MutableList<UpsertMedicalResourceRequest!>: List of upsert requests. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<MutableList<MedicalResource!>!, HealthConnectException!>: Callback to receive result of performing this operation. This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if any requests contains invalid MedicalDataSource IDs.