# HealthConnectClient.Companion

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

*** ** * ** ***


```
public static class HealthConnectClient.Companion
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html` | `https://developer.android.com/reference/androidx/health/connect/client/HealthConnectClient#getHealthConnectManageDataIntent(android.content.Context,kotlin.String)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html providerPackageName )` Intent to open Health Connect data management screen on this phone. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/health/connect/client/HealthConnectClient#getHealthConnectSettingsAction()()` Intent action to open Health Connect settings on this phone. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/health/connect/client/HealthConnectClient` | `https://developer.android.com/reference/androidx/health/connect/client/HealthConnectClient#getOrCreate(android.content.Context,kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html providerPackageName)` Retrieves an IPC-backed `https://developer.android.com/reference/androidx/health/connect/client/HealthConnectClient` instance binding to an available implementation. |
| `static final int` | `https://developer.android.com/reference/androidx/health/connect/client/HealthConnectClient#getSdkStatus(android.content.Context,kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html providerPackageName)` Determines whether the Health Connect SDK is available on this device at the moment. |

## Public methods

### getHealthConnectManageDataIntent

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

```
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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html providerPackageName` | optional alternative package provider to choose for backend implementation |

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

### getHealthConnectSettingsAction

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

```
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](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

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

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html providerPackageName` | optional alternative package provider to choose for backend implementation |

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

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

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

### getSdkStatus

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

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

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

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

Value is one of the following:

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

<br />

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html providerPackageName` | optional package provider to choose for backend implementation |

| Returns |
|---|---|
| `int` | One of `https://developer.android.com/reference/androidx/health/connect/client/HealthConnectClient#SDK_UNAVAILABLE()`, `https://developer.android.com/reference/androidx/health/connect/client/HealthConnectClient#SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED()`, or `https://developer.android.com/reference/androidx/health/connect/client/HealthConnectClient#SDK_AVAILABLE()` |