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

Get started on Android

This guide explains how to start development with Google Fit on Android.

Setup

Before you start to build your app, complete the steps in the following sections.

Get a Google Account

To use the Google Fit APIs, you need a Google Account. You can create a new account or use an existing account. You might want to create a separate account to test your app from a user's perspective.

Get Google Play services

Get 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 isn't Installed, select them both and click Install Packages.

Get an OAuth 2.0 client ID

To enable the Fitness API, get an OAuth 2.0 client ID.

Create and configure your project

To build an app with the Fitness API, we recommend that you use the Android Studio development environment. For details on how to make a new project and configure it in Android Studio, see Create a project.

Add the Google Play services client library

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

Kotlin DSL

plugin {
    id("com.android.application")
}

...

dependencies {
        implementation("com.google.android.gms:play-services-fitness:20.0.0")
        implementation("com.google.android.gms:play-services-auth:19.0.0")
}

Groovy DSL

apply plugin: 'com.android.application'

...

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

This makes sure that Gradle automatically downloads the fitness SDK when it builds your app.

Build and test your app

After you finish the setup steps, you can start to build your app. To get started, learn about the types of data your app can store and read, as well as how to work with data in Google Fit.

Get the necessary Android permissions

To read and write some types of data, your app needs to request Android permissions.

Get OAuth permissions

The data types that your app has permission to access correspond to authorization scopes. To ask for these permissions, you need to add which data types your app needs access to in a FitnessOptions instance. When your app asks to use any of the Google Fit data types, the Android SDK automatically checks which scopes they belong to and asks the user for authorization to those scopes.

Create an API client

Create an API client and add the data types that your app needs to access to write or read data. The following data types are available:

  • SensorsClient: Access different sources of health and wellness data from hardware sensors in the local device and in companion devices.
  • RecordingClient: For low-power, always-on background collection of sensor data.
  • HistoryClient: Insert, delete, and read historical data in Google Fit.
  • SessionsClient: Create and manage Sessions of user activity.
  • GoalsClient: Read Heart Point and Steps goals created by users in Google Fit.
  • ConfigClient: Access custom data types and settings in the Google Fit platform.

For an example, see Create a Fitness API client.

Resulting user authorization flow

The following shows the resulting authorization flow that users experience when they're asked for permissions:

Figure 1.The authorization flow for users.
  1. Request Android permissions: After your app is downloaded, it requests any runtime permissions that it needs, and users grant or deny these permissions.
  2. Connect: Your app checks whether permissions were granted before it requests access to other data types.
  3. OAuth scopes request: Google prompts the user to grant your app the OAuth scopes needed for the data types it has requested access to.
  4. Access applied: After the user grants permissions, your app can access the data types that were requested.

Apply for verification

After you build and test your app, you need to apply for verification with different levels of justification needed for sensitive and restricted scopes.