ExerciseClient

interface ExerciseClient


Client which provides a way to subscribe to the health data of a device during an exercise.

Summary

Public fields

abstract @NonNull ListenableFuture<@NonNull ExerciseCapabilities>

Returns the ExerciseCapabilities of this client for the device.

abstract @NonNull ListenableFuture<@NonNull ExerciseInfo>

Returns the ExerciseInfo.

Public methods

abstract @NonNull ListenableFuture<@NonNull Void>

Adds an ExerciseGoal for an active exercise.

abstract @NonNull ListenableFuture<@NonNull Void>

Clears the listener set using setUpdateListener.

abstract @NonNull ListenableFuture<@NonNull Void>

Ends the current exercise, if it has been started.

abstract @NonNull ListenableFuture<@NonNull Void>

Ends the current lap, calls ExerciseStateListener.onLapSummary with data spanning the marked lap and starts a new lap.

abstract @NonNull ListenableFuture<@NonNull Void>

Enables or disables the auto pause/resume for the current exercise.

abstract @NonNull ListenableFuture<@NonNull Void>

Pauses the current exercise, if it is currently started.

abstract @NonNull ListenableFuture<@NonNull Void>

Resumes the current exercise, if it is currently paused.

abstract @NonNull ListenableFuture<@NonNull Void>

Sets the listener for the current ExerciseUpdate.

abstract @NonNull ListenableFuture<@NonNull Void>
setUpdateListener(
    @NonNull ExerciseUpdateListener listener,
    @NonNull Executor executor
)

Calls to the listener will be executed using the specified Executor.

abstract @NonNull ListenableFuture<@NonNull Void>

Starts a new exercise.

Public fields

capabilities

@NonNull
public abstract @NonNull ListenableFuture<@NonNull ExerciseCapabilitiescapabilities

Returns the ExerciseCapabilities of this client for the device.

currentExerciseInfo

@NonNull
public abstract @NonNull ListenableFuture<@NonNull ExerciseInfocurrentExerciseInfo

Returns the ExerciseInfo.

Public methods

addGoalToActiveExercise

@NonNull
public abstract ListenableFuture<@NonNull VoidaddGoalToActiveExercise(@NonNull ExerciseGoal exerciseGoal)

Adds an ExerciseGoal for an active exercise.

An ExerciseGoal is a one-time goal, such as achieving a target total step count.

Goals apply to only active exercises owned by the client, and will be invalidated once the exercise is complete.

Returns
ListenableFuture<@NonNull Void>

a ListenableFuture that completes once the exercise goal has been added. This returned ListenableFuture fails if the exercise is not active.

clearUpdateListener

@NonNull
public abstract ListenableFuture<@NonNull VoidclearUpdateListener(@NonNull ExerciseUpdateListener listener)

Clears the listener set using setUpdateListener.

If the listener wasn't set, the returned ListenableFuture will fail.

endExercise

@NonNull
public abstract ListenableFuture<@NonNull VoidendExercise()

Ends the current exercise, if it has been started. If the exercise has ended then this future will fail.

No additional metrics will be produced for the exercise and any on device persisted data about the exercise will be deleted after the summary has been sent back.

markLap

@NonNull
public abstract ListenableFuture<@NonNull VoidmarkLap()

Ends the current lap, calls ExerciseStateListener.onLapSummary with data spanning the marked lap and starts a new lap. If the exercise supports laps this method can be called at any point after an exercise has been started and before it has been ended regardless of the exercise status.

The metrics in the lap summary will start from either the start time of the exercise or the last time a lap was marked to the time this method is being called.

If there's no exercise being tracked or if the exercise does not support laps then this future will fail.

overrideAutoPauseAndResumeForActiveExercise

@NonNull
public abstract ListenableFuture<@NonNull VoidoverrideAutoPauseAndResumeForActiveExercise(boolean enabled)

Enables or disables the auto pause/resume for the current exercise.

Parameters
boolean enabled

a boolean to indicate if should be enabled or disabled

pauseExercise

@NonNull
public abstract ListenableFuture<@NonNull VoidpauseExercise()

Pauses the current exercise, if it is currently started.

While the exercise is paused active time and cumulative metrics such as distance will not accumulate. Instantaneous measurements such as speed and heart rate will continue to update if requested in the ExerciseConfig.

If the exercise remains paused for a long period of time, Health Services will reduce or suspend access to sensors and GPS in order to conserve battery. Should this happen, access will automatically resume when the exercise is resumed.

If the exercise is already paused then this method has no effect. If the exercise has ended then the returned future will fail.

Returns
ListenableFuture<@NonNull Void>

a ListenableFuture that completes once the exercise has been paused.

resumeExercise

@NonNull
public abstract ListenableFuture<@NonNull VoidresumeExercise()

Resumes the current exercise, if it is currently paused.

Once resumed active time and cumulative metrics such as distance will resume accumulating.

If the exercise has been started but is not currently paused this method has no effect. If the exercise has ended then the returned future will fail.

Returns
ListenableFuture<@NonNull Void>

a ListenableFuture that completes once the exercise has been resumed.

setUpdateListener

@NonNull
public abstract ListenableFuture<@NonNull VoidsetUpdateListener(@NonNull ExerciseUpdateListener listener)

Sets the listener for the current ExerciseUpdate.

This listener won't be called until an exercise is in progress. It will also only receive updates from exercises tracked in this app.

If an exercise is in progress, the ExerciseUpdateListener is immediately called with the associated ExerciseUpdate, and subsequently whenever the state is updated or an event is triggered.

Calls to the listener will be executed on the main application thread. To control where to execute the listener, see the overload taking an Executor. To remove the listener use clearUpdateListener.

setUpdateListener

@NonNull
public abstract ListenableFuture<@NonNull VoidsetUpdateListener(
    @NonNull ExerciseUpdateListener listener,
    @NonNull Executor executor
)

Calls to the listener will be executed using the specified Executor. To execute the listener on the main application thread use the overload without the Executor.

startExercise

@NonNull
public abstract ListenableFuture<@NonNull VoidstartExercise(@NonNull ExerciseConfig configuration)

Starts a new exercise.

Once started, Health Services will begin collecting data associated with the exercise.

Since Health Services only allows a single active exercise at a time, this will terminate any active exercise currently in progress before starting the new one.

Returns
ListenableFuture<@NonNull Void>

a ListenableFuture that completes once the exercise has been started.