Google is committed to advancing racial equity for Black communities. See how.


public interface GoalsApi

This interface is deprecated.
Use GoalsClient.

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

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

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

     GoogleApiClient client = new GoogleApiClient.Builder(context)
         .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
         .addScope(new Scope(Scopes.FITNESS_LOCATION_READ))

     PendingResult<GoalsResult> pendingResult =
             new GoalsReadRequest.Builder()

     GoalsResult readDataResult = pendingResult.await();
     List<Goal> goals = readDataResult.getGoals();

This API can be combined with a subscription in the Recording Api 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();
    PendingResult<DataReadResult> pendingResult = Fitness.HistoryApi.readData(
        new DataReadRequest.Builder()
                goal.getStartTime(current, TimeUnit.NANOSECONDS),
                goal.getEndTime(current, TimeUnit.NANOSECONDS),
    DataReadResult stepReadResult = pendingResult.await();
    List<DataPoint> dataPoints =

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

Public Method Summary

abstract PendingResult<GoalsResult>
readCurrentGoals(GoogleApiClient client, GoalsReadRequest request)
Reads current goals from the user's Google Fit store.

Public Methods

public abstract PendingResult<GoalsResult> readCurrentGoals (GoogleApiClient client, GoalsReadRequest request)

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

client An existing GoogleApiClient. It does not need to be connected at the time of this call, but the read operation will be delayed until the connection is complete.
  • A pending result containing current goals.