MeasureClient
interface MeasureClient
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 ExerciseClient or PassiveMonitoringClient depending on your use case).
Existing subscriptions made with the PassiveMonitoringClient are also expected to get the data generated by this client.
Summary
Public functions |
|
|---|---|
ListenableFuture<MeasureCapabilities> |
Returns the |
Unit |
registerMeasureCallback(Registers the app for live measurement of the specified |
Unit |
registerMeasureCallback(Same as |
ListenableFuture<Void> |
unregisterMeasureCallbackAsync(Unregisters the given |
Extension functions |
|
|---|---|
suspend MeasureCapabilities |
Returns the |
suspend Void |
MeasureClient.unregisterMeasureCallback(Unregisters the given |
Public functions
getCapabilitiesAsync
fun getCapabilitiesAsync(): ListenableFuture<MeasureCapabilities>
Returns the MeasureCapabilities of this client for the device.
This can be used to determine what DeltaDataTypes this device supports for live measurement. Clients should use the capabilities to inform their requests since Health Services will typically reject requests made for DeltaDataTypes which are not enabled for measurement.
| Returns | |
|---|---|
ListenableFuture<MeasureCapabilities> |
a |
registerMeasureCallback
fun registerMeasureCallback(
dataType: DeltaDataType<*, *>,
callback: MeasureCallback
): Unit
Registers the app for live measurement of the specified DeltaDataType.
The callback will be called on the main application thread. To move calls to an alternative thread use registerMeasureCallback.
Even if data is registered for live capture, it can still be sent out in batches depending on the application processor state.
Registering a 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 DeltaDataType is supported on this device by checking the 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 unregisterMeasureCallbackAsync is called.
If the same callback is already registered for the given DeltaDataType, this operation is a no-op.
| Parameters | |
|---|---|
dataType: DeltaDataType<*, *> |
the |
callback: MeasureCallback |
the |
registerMeasureCallback
fun registerMeasureCallback(
dataType: DeltaDataType<*, *>,
executor: Executor,
callback: MeasureCallback
): Unit
Same as registerMeasureCallback, except the callback is called on the given Executor.
| Parameters | |
|---|---|
dataType: DeltaDataType<*, *> |
the |
executor: Executor |
|
callback: MeasureCallback |
the |
unregisterMeasureCallbackAsync
fun unregisterMeasureCallbackAsync(
dataType: DeltaDataType<*, *>,
callback: MeasureCallback
): ListenableFuture<Void>
Unregisters the given MeasureCallback for updates of the given DeltaDataType.
| Parameters | |
|---|---|
dataType: DeltaDataType<*, *> |
the |
callback: MeasureCallback |
the |
| Returns | |
|---|---|
ListenableFuture<Void> |
a |
Extension functions
MeasureClient.getCapabilities
suspend fun MeasureClient.getCapabilities(): MeasureCapabilities
Returns the MeasureCapabilities of this client for the device.
This can be used to determine what DeltaDataTypes this device supports for live measurement. Clients should use the capabilities to inform their requests since Health Services will typically reject requests made for DeltaDataTypes which are not enabled for measurement.
| Returns | |
|---|---|
MeasureCapabilities |
a |
| Throws | |
|---|---|
HealthServicesException |
if Health Service fails to process the call |
MeasureClient.unregisterMeasureCallback
suspend fun MeasureClient.unregisterMeasureCallback(
dataType: DeltaDataType<*, *>,
callback: MeasureCallback
): Void
Unregisters the given MeasureCallback for updates of the given DeltaDataType.
| Parameters | |
|---|---|
dataType: DeltaDataType<*, *> |
the |
callback: MeasureCallback |
the |
| Throws | |
|---|---|
HealthServicesException |
if Health Service fails to process the call |