androidx.health.connect.client


Interfaces

HealthConnectClient

Interface to access health and fitness records.

HealthConnectFeatures

Interface for checking availability of features in HealthConnectClient.

PermissionController

Interface for operations related to permissions.

Extension functions summary

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

Deletes any Record of type T in the given timeRangeFilter (automatically filtered to Record belonging to the calling application).

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

Deletes one or more Record by their identifiers.

suspend inline ReadRecordResponse<T>

Reads one Record point of type T and with the specified recordId.

Extension functions

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

Deletes any Record of type T in the given timeRangeFilter (automatically filtered to Record belonging to the calling application). Deletion of multiple Record is executed in a transaction - if one fails, none is deleted.

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

healthConnectClient.deleteRecords<StepsRecord>(
    timeRangeFilter = TimeRangeFilter.between(startTime, endTime)
)
Parameters
<T : Record>

Which type of Record to delete, such as Steps.

timeRangeFilter: TimeRangeFilter

The TimeRangeFilter to delete from

Throws
android.os.RemoteException

For any IPC transportation failures.

java.lang.SecurityException

For requests with unpermitted access.

java.io.IOException

For any disk I/O issues.

kotlin.IllegalStateException

If service is not available.

See also
deleteRecords

Example usage to delete written steps data in a time range:

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

Deletes one or more Record by their identifiers. Deletion of multiple Record is executed in single transaction - if one fails, none is deleted.

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

healthConnectClient.deleteRecords<StepsRecord>(
    recordIdsList = listOf(uid1, uid2),
    clientRecordIdsList = emptyList()
)
Parameters
<T : Record>

Which type of Record to delete, such as Steps.

recordIdsList: List<String>

List of androidx.health.connect.client.records.metadata.Metadata.id of Record to delete

clientRecordIdsList: List<String>

List of client record IDs of Record to delete

Throws
android.os.RemoteException

For any IPC transportation failures. Deleting by invalid identifiers such as a non-existing identifier or deleting the same record multiple times will result in IPC failure.

java.lang.SecurityException

For requests with unpermitted access.

java.io.IOException

For any disk I/O issues.

kotlin.IllegalStateException

If service is not available.

See also
deleteRecords

Example usage to delete written steps data by its unique identifier:

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

Reads one Record point of type T and with the specified recordId.

Parameters
<T : Record>

Which type of Record to read, such as Steps.

recordId: String

androidx.health.connect.client.records.metadata.Metadata.id of Record to read

Returns
ReadRecordResponse<T>

The Record data point.

Throws
android.os.RemoteException

For any IPC transportation failures. Update with invalid identifiers will result in IPC failure.

java.lang.SecurityException

For requests with unpermitted access.

java.io.IOException

For any disk I/O issues.

kotlin.IllegalStateException

If service is not available.

See also
readRecord