# MeasureClient

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

*** ** * ** ***

<br />

```
interface MeasureClient
```

<br />

*** ** * ** ***

Client which provides a way to make measurements of health data on a device.

This is optimized for apps to register live callbacks on data which may be sampled at a faster rate; this is not meant to be used for long-lived subscriptions to data (for this, consider using `https://developer.android.com/reference/kotlin/androidx/health/services/client/ExerciseClient` or `https://developer.android.com/reference/kotlin/androidx/health/services/client/PassiveMonitoringClient` depending on your use case).

Existing subscriptions made with the `https://developer.android.com/reference/kotlin/androidx/health/services/client/PassiveMonitoringClient` are also expected to get the data generated by this client.

## Summary

| ### Public functions |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/health/services/client/data/MeasureCapabilities>` | `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#getCapabilitiesAsync()()` Returns the `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/MeasureCapabilities` of this client for the device. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#registerMeasureCallback(androidx.health.services.client.data.DeltaDataType,androidx.health.services.client.MeasureCallback)( dataType: https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType<*, *>, callback: https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback )` Registers the app for live measurement of the specified `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#registerMeasureCallback(androidx.health.services.client.data.DeltaDataType,java.util.concurrent.Executor,androidx.health.services.client.MeasureCallback)( dataType: https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType<*, *>, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, callback: https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback )` Same as `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#registerMeasureCallback(androidx.health.services.client.data.DeltaDataType,java.util.concurrent.Executor,androidx.health.services.client.MeasureCallback)`, except the `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#registerMeasureCallback(androidx.health.services.client.data.DeltaDataType,java.util.concurrent.Executor,androidx.health.services.client.MeasureCallback)` is called on the given `https://developer.android.com/reference/java/util/concurrent/Executor.html`. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#unregisterMeasureCallbackAsync(androidx.health.services.client.data.DeltaDataType,androidx.health.services.client.MeasureCallback)( dataType: https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType<*, *>, callback: https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback )` Unregisters the given `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` for updates of the given `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType`. |

| ### Extension functions |
|---|---|
| `suspend https://developer.android.com/reference/kotlin/androidx/health/services/client/data/MeasureCapabilities` | `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient.https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#(androidx.health.services.client.MeasureClient).getCapabilities()()` Returns the `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/MeasureCapabilities` of this client for the device. |
| `suspend https://developer.android.com/reference/java/lang/Void.html` | `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient.https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#(androidx.health.services.client.MeasureClient).unregisterMeasureCallback(androidx.health.services.client.data.DeltaDataType,androidx.health.services.client.MeasureCallback)( dataType: https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType<*, *>, callback: https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback )` Unregisters the given `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` for updates of the given `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType`. |

## Public functions

### getCapabilitiesAsync

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

```
fun getCapabilitiesAsync(): ListenableFuture<MeasureCapabilities>
```

Returns the `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/MeasureCapabilities` of this client for the device.

This can be used to determine what `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType`s this device supports for live measurement. Clients should use the capabilities to inform their requests since Health Services will typically reject requests made for `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType`s which are not enabled for measurement.

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/health/services/client/data/MeasureCapabilities>` | a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` containing the `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/MeasureCapabilities` for this device |

### registerMeasureCallback

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

```
fun registerMeasureCallback(
    dataType: DeltaDataType<*, *>,
    callback: MeasureCallback
): Unit
```

Registers the app for live measurement of the specified `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType`.

The callback will be called on the main application thread. To move calls to an alternative thread use `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#registerMeasureCallback(androidx.health.services.client.data.DeltaDataType,androidx.health.services.client.MeasureCallback)`.

Even if data is registered for live capture, it can still be sent out in batches depending on the application processor state.

Registering a `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType` for live measurement capture is expected to increase the sample rate on the associated sensor(s); this is typically used for one-off measurements. Do not use this method for background capture or workout tracking. The client is responsible for ensuring that their requested `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType` is supported on this device by checking the `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/MeasureCapabilities`. The returned future will fail if the request is not supported on a given device.

The callback will continue to be called until the app is killed or `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#unregisterMeasureCallbackAsync(androidx.health.services.client.data.DeltaDataType,androidx.health.services.client.MeasureCallback)` is called.

If the same `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#registerMeasureCallback(androidx.health.services.client.data.DeltaDataType,androidx.health.services.client.MeasureCallback)` is already registered for the given `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType`, this operation is a no-op.

| Parameters |
|---|---|
| `dataType: https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType<*, *>` | the `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType` that needs to be measured |
| `callback: https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` | the `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` to receive updates from Health Services |

### registerMeasureCallback

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

```
fun registerMeasureCallback(
    dataType: DeltaDataType<*, *>,
    executor: Executor,
    callback: MeasureCallback
): Unit
```

Same as `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#registerMeasureCallback(androidx.health.services.client.data.DeltaDataType,java.util.concurrent.Executor,androidx.health.services.client.MeasureCallback)`, except the `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#registerMeasureCallback(androidx.health.services.client.data.DeltaDataType,java.util.concurrent.Executor,androidx.health.services.client.MeasureCallback)` is called on the given `https://developer.android.com/reference/java/util/concurrent/Executor.html`.

| Parameters |
|---|---|
| `dataType: https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType<*, *>` | the `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType` that needs to be measured |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | the `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureClient#registerMeasureCallback(androidx.health.services.client.data.DeltaDataType,java.util.concurrent.Executor,androidx.health.services.client.MeasureCallback)` will be invoked |
| `callback: https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` | the `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` to receive updates from Health Services |

### unregisterMeasureCallbackAsync

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

```
fun unregisterMeasureCallbackAsync(
    dataType: DeltaDataType<*, *>,
    callback: MeasureCallback
): ListenableFuture<Void>
```

Unregisters the given `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` for updates of the given `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType`.

| Parameters |
|---|---|
| `dataType: https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType<*, *>` | the `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType` that needs to be unregistered |
| `callback: https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` | the `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` which was used in registration |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` that completes when the un-registration succeeds in Health Services. This is a no-op if the callback has already been unregistered. |

## Extension functions

### MeasureClient.getCapabilities

Artifact: [androidx.health:health-services-client](https://developer.android.com/jetpack/androidx/releases/health) [View Source](https://cs.android.com/search?q=file:androidx/health/services/client/MeasureClientExtension.kt+function:getCapabilities)

```
suspend fun MeasureClient.getCapabilities(): MeasureCapabilities
```

Returns the `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/MeasureCapabilities` of this client for the device.

This can be used to determine what `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType`s this device supports for live measurement. Clients should use the capabilities to inform their requests since Health Services will typically reject requests made for `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType`s which are not enabled for measurement.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/MeasureCapabilities` | a `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/MeasureCapabilities` for this device |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/services/client/HealthServicesException` | if Health Service fails to process the call |

### MeasureClient.unregisterMeasureCallback

Artifact: [androidx.health:health-services-client](https://developer.android.com/jetpack/androidx/releases/health) [View Source](https://cs.android.com/search?q=file:androidx/health/services/client/MeasureClientExtension.kt+function:unregisterMeasureCallback)

```
suspend fun MeasureClient.unregisterMeasureCallback(
    dataType: DeltaDataType<*, *>,
    callback: MeasureCallback
): Void
```

Unregisters the given `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` for updates of the given `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType`.

| Parameters |
|---|---|
| `dataType: https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType<*, *>` | the `https://developer.android.com/reference/kotlin/androidx/health/services/client/data/DeltaDataType` that needs to be unregistered |
| `callback: https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` | the `https://developer.android.com/reference/kotlin/androidx/health/services/client/MeasureCallback` which was used in registration |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/services/client/HealthServicesException` | if Health Service fails to process the call |