HealthConnectClient.Companion


public static class HealthConnectClient.Companion


Summary

Public methods

static final @NonNull Intent
getHealthConnectManageDataIntent(
    @NonNull Context context,
    @NonNull String providerPackageName
)

Intent to open Health Connect data management screen on this phone.

static final @NonNull String

Intent action to open Health Connect settings on this phone.

static final @NonNull HealthConnectClient
getOrCreate(@NonNull Context context, @NonNull String providerPackageName)

Retrieves an IPC-backed HealthConnectClient instance binding to an available implementation.

static final int
getSdkStatus(@NonNull Context context, @NonNull String providerPackageName)

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

Public methods

getHealthConnectManageDataIntent

Added in 1.1.0-alpha10
public static final @NonNull Intent getHealthConnectManageDataIntent(
    @NonNull Context context,
    @NonNull String providerPackageName
)

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

Parameters
@NonNull Context context

the context

@NonNull String providerPackageName

optional alternative package provider to choose for backend implementation

Returns
@NonNull Intent

Intent to open Health Connect data management screen.

getHealthConnectSettingsAction

Added in 1.1.0-alpha10
public static final @NonNull String getHealthConnectSettingsAction()

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

getOrCreate

Added in 1.1.0-alpha10
public static final @NonNull HealthConnectClient getOrCreate(@NonNull Context context, @NonNull String providerPackageName)

Retrieves an IPC-backed HealthConnectClient instance binding to an available implementation.

Parameters
@NonNull Context context

the context

@NonNull String providerPackageName

optional alternative package provider to choose for backend implementation

Returns
@NonNull HealthConnectClient

instance of HealthConnectClient ready for issuing requests

Throws
kotlin.UnsupportedOperationException

if service not available due to SDK version too low or running in a profile

kotlin.IllegalStateException

if the SDK is not available

See also
getSdkStatus

getSdkStatus

Added in 1.1.0-alpha10
public static final int getSdkStatus(@NonNull Context context, @NonNull String providerPackageName)

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

import androidx.health.connect.client.HealthConnectClient

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

the context

@NonNull String providerPackageName

optional package provider to choose for backend implementation