Work with Fitness Goals

Goals provide a way for Google Fit users to track their health and fitness progress. The Goals API enables your app to read user goals, and use this data to enhance the user's experience by providing updates and insights related to the user's progress.

Read goals data

To get a list of user goals:

The following example shows creating a new Fitness client and getting a list of user goals for TYPE_STEP_COUNT_DELTA and TYPE_DISTANCE_DELTA data types:

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();

Once you've got the user's goals data, you can use the History API to query for progress. The following example demonstrates reading the user's step data and calculating their current progress toward their step goal (it is assumed that your app has already used the Recording API to subscribe to the TYPE_STEP_COUNT_DELTA data type):

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.getValues()[0].asInt();
double progress = total / goal.getMetricObjective().getValue();

Send feedback about...