We're making some changes to the Google Fit APIs. Learn about how these changes might affect your app. Read our new policy.

Getting Started on Android

This guide explains how to start developing with Google Fit on Android. Google Fit is part of Google Play services.


Get a Google Account

To use the Google Fit APIs, you need a Google Account. If you already have an account, then you're all set. You may also want to create a separate Google Account for testing purposes.

Get Google Play services

Google Fit is available on Android devices with Google Play services 7.0 or higher. Devices running Android 2.3 or higher that have the Google Play Store app automatically receive updates to Google Play services.

To check which version of Google Play services is installed on your device, go to Settings > Apps > Google Play services.

Ensure that you have the latest client library for Google Play services on your development host:

  1. Open the Android SDK Manager.
  2. Under SDK Tools, find Google Play services.
  3. If the status for these packages is different than Installed, select them both and click Install Packages.

Get an OAuth 2.0 client ID

If you haven't already enabled the Fitness API and obtained an OAuth 2.0 client ID, follow the instructions in Get an OAuth 2.0 Client ID to do so now.

Configure your project

Android Studio is the recommended development environment for building an app with the Fitness API. To create a new project, follow the steps described in Creating a Project.

In the IDE, open the build.gradle file for your module and add the Google Play services client library as a dependency:

apply plugin: 'com.android.application'


dependencies {
    implementation 'com.google.android.gms:play-services-fitness:19.0.0'
    implementation 'com.google.android.gms:play-services-auth:18.1.0'

Connect to the fitness service

To connect to the fitness service before you can use it, complete these steps:

  1. Get the necessary Android permissions: To use any of these data types you need the relevant Android permission. Read the Authorization guide to learn how to do this.

  2. Apply for OAuth verification: Each data type you want to read or write corresponds to an authorization scope. For your app to read or write data types, you need to apply for verification with different levels of justification needed for sensitive and restricted scopes.

  3. Create an API client and use APIs: Once your app is verified and has obtained the necessary Android permissions, create a fitness client to write and/or read data:


Create the API client as follows:

  1. Create a FitnessOptions instance, declaring the data types and access type (read and/or write) your app needs:

    FitnessOptions fitnessOptions = FitnessOptions.builder()
            .addDataType(DataType.TYPE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
            .addDataType(DataType.AGGREGATE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
  2. Get an instance of the Account object to use with the API:

    GoogleSignInAccount account = GoogleSignIn.getAccountForExtension(this, fitnessOptions);
  3. Check if the user has previously granted the necessary data access, and if not, initiate the authorization flow:

    if (!GoogleSignIn.hasPermissions(account, fitnessOptions)) {
                this, // your activity
                GOOGLE_FIT_PERMISSIONS_REQUEST_CODE, // e.g. 1
    } else {
  4. If the authorization flow is required, handle the user's response:

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == GOOGLE_FIT_PERMISSIONS_REQUEST_CODE) {
  5. After the user has authorized access to the data requested, create a fitness client (for example, a HistoryClient to read and/or write historic fitness data) based on your app's purpose and needs:

    private void accessGoogleFit() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        long endTime = cal.getTimeInMillis();
        cal.add(Calendar.YEAR, -1);
        long startTime = cal.getTimeInMillis();
        DataReadRequest readRequest = new DataReadRequest.Builder()
                .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
                .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                .bucketByTime(1, TimeUnit.DAYS)
        GoogleSignInAccount account = GoogleSignIn
                .getAccountForExtension(this, fitnessOptions);
        Fitness.getHistoryClient(this, account)
                .addOnSuccessListener(response -> {
                    // Use response data here
                    Log.d(TAG, "OnSuccess()");
                .addOnFailureListener(e -> {
                    Log.d(TAG, "OnFailure()", e);