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 fields

abstract @NonNull ListenableFuture<@NonNull MeasureCapabilities>

Returns the MeasureCapabilities of this client for the device.

Public methods

abstract @NonNull ListenableFuture<@NonNull Void>
registerCallback(
    @NonNull DataType dataType,
    @NonNull MeasureCallback callback
)

Registers the app for live measurement of the specified DataType.

abstract @NonNull ListenableFuture<@NonNull Void>
registerCallback(
    @NonNull DataType dataType,
    @NonNull MeasureCallback callback,
    @NonNull Executor executor
)

Same as registerCallback, except the callback is called on the given Executor.

abstract @NonNull ListenableFuture<@NonNull Void>
unregisterCallback(
    @NonNull DataType dataType,
    @NonNull MeasureCallback callback
)

Unregisters the given MeasureCallback for updates of the given DataType.

Public fields

capabilities

@NonNull
public abstract @NonNull ListenableFuture<@NonNull MeasureCapabilitiescapabilities

Returns the MeasureCapabilities of this client for the device.

Public methods

registerCallback

@NonNull
public abstract ListenableFuture<@NonNull VoidregisterCallback(
    @NonNull DataType dataType,
    @NonNull MeasureCallback callback
)

Registers the app for live measurement of the specified DataType.

The callback will be called on the main application thread. To move calls to an alternative thread use registerCallback.

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

Registering a DataType 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 callback will continue to be called until the app is killed or unregisterCallback is called.

If the same callback is already registered for the given DataType, this operation is a no-op.

registerCallback

@NonNull
public abstract ListenableFuture<@NonNull VoidregisterCallback(
    @NonNull DataType dataType,
    @NonNull MeasureCallback callback,
    @NonNull Executor executor
)

Same as registerCallback, except the callback is called on the given Executor.

unregisterCallback

@NonNull
public abstract ListenableFuture<@NonNull VoidunregisterCallback(
    @NonNull DataType dataType,
    @NonNull MeasureCallback callback
)

Unregisters the given MeasureCallback for updates of the given DataType.