public class GoalsClient extends GoogleApi<FitnessOptions>

Client for reading fitness Goals created by users in Google Fit.

The readCurrentGoals(GoalsReadRequest) method should be used whenever goals are needed.

The Goals Client should be accessed via the Fitness entry point. Example:

    GoogleSignInOptionsExtension fitnessOptions =
          .addDataType(DataType.TYPE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
          .addDataType(DataType.TYPE_DISTANCE_DELTA, FitnessOptions.ACCESS_READ)

    GoogleSignInAccount gsa = GoogleSignIn.getAccountForExtension(this, fitnessOptions);

    Task<List<Goal>> response = Fitness.getGoalsClient(this, gsa)
        .readCurrentGoals(new GoalsReadRequest.Builder()

    List<Goal> goals = Tasks.await(response);

This Client can be combined with a subscription in the Recording Client to collect goal progress data in the background and query it later for displaying. A simple progress query example for a step metric goal:

    Calendar current = Calendar.getInstance();
    Task<DataReadResponse> response = Fitness.getHistoryClient(this, googleSigninAccount)
        .readData(new DataReadRequest.Builder()
                goal.getStartTime(current, TimeUnit.NANOSECONDS),
                goal.getEndTime(current, TimeUnit.NANOSECONDS),
    DataReadResponse stepReadResponse = Tasks.await(response);
    List<DataPoint> dataPoints =

    int total = 0;
    for (DataPoint dataPoint : dataPoints) {
      total += dataPoint.getValues()[0].asInt();
    double progress = total / goal.getMetricObjective().getValue();

Inherited Field Summary

Public Method Summary

readCurrentGoals(GoalsReadRequest request)
Reads current goals from the user’s Google Fit store.

Inherited Method Summary

Public Methods

public Task<List<Goal>> readCurrentGoals (GoalsReadRequest request)

Reads current goals from the user’s Google Fit store.

  • Task containing current goals.