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

> [!NOTE]
> **Note:** Google Fit is part of Google Play services. [Learn about the
> benefits your app gets from using Google Play
> Services](https://developers.google.com/android/guides/overview).

## 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](https://www.google.com/accounts/NewAccount) 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](https://developer.android.com/studio/intro/update#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](https://developers.google.com/fit/android/get-api-key.md.txt).

### Create and configure your project

We recommend using the [Android Studio development environment](https://developer.android.com/studio) to build an app with the Fitness API. For
details on how to make a new project and configure it in Android Studio, see
[Create a project](https://developer.android.com/studio/projects/create-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

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

...

dependencies {
        implementation("com.google.android.gms:play-services-fitness:21.3.0")
        implementation("com.google.android.gms:play-services-auth:22.0.0")
}
```

### Groovy DSL

```
apply plugin: 'com.android.application'

...

dependencies {
    implementation 'com.google.android.gms:play-services-fitness:21.3.0'
    implementation 'com.google.android.gms:play-services-auth:22.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](https://developers.google.com/fit/datatypes.md.txt) your app can [store and
read](https://developers.google.com/fit/datatypes#using_data_types). Learn more about [working with
data](https://developers.google.com/fit/android/history) in Google Fit.

### Get the necessary Android permissions

To read and write [some types of data](https://developers.google.com/fit/android/authorization#data_types_that_ne
ed_android_permissions), your app needs to [request Android permissions](https://developers.google.com/fit/android/authorization#android_permission
s).

### Get OAuth permissions

The data types that your app has permission to access correspond to
[authorization scopes](https://developers.google.com/fit/datatypes.md.txt#authorization_scopes). To ask
for these permissions, you need to [add
which data types your app needs access to in a `FitnessOptions`
instance](https://developers.google.com/fit/android/api-client-example). 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 endpoints are available:

- [`SensorsClient`](https://developers.google.com/android/reference/com/google/android/gms/fitness/SensorsClient.md.txt): Access different sources of health and wellness data from hardware sensors in the local device and in companion devices.
- [`RecordingClient`](https://developers.google.com/android/reference/com/google/android/gms/fitness/RecordingClient.md.txt): For low-power, always-on background collection of sensor data.
- [`HistoryClient`](https://developers.google.com/android/reference/com/google/android/gms/fitness/HistoryClient.md.txt): Insert, delete, and read historical data in Google Fit.
- [`SessionsClient`](https://developers.google.com/android/reference/com/google/android/gms/fitness/SessionsClient.md.txt): Create and manage [Sessions](https://developers.google.com/fit/sessions.md.txt) of user activity.
- [`GoalsClient`](https://developers.google.com/android/reference/com/google/android/gms/fitness/GoalsClient.md.txt): Read Heart Point and Steps goals created by users in Google Fit.
- [`ConfigClient`](https://developers.google.com/android/reference/com/google/android/gms/fitness/ConfigClient.md.txt): Access custom data types and settings in the Google Fit platform.

[See an example of how to build a Fitness API client.](https://developers.google.com/fit/android/api-client-example.md.txt)

### Resulting user authorization flow

The following shows the resulting authorization flow that users experience
when they're asked for permissions:
![](https://developers.google.com/static/fit/images/userflow.png) **Figure 1.**The authorization flow for users.

1. **Android permissions**: Users see what Android permissions your app has requested before downloading it. After your app is downloaded, it requests any runtime permissions that it needs, and users grant or deny these permissions.
2. **Check and 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 that it wants to access.
4. **Access applied**: After the user grants permissions, your app can access the data types that belong to the scopes that the user has granted permission for.

## Apply for verification

After you build and test your app, you need to [apply for
verification](https://developers.google.com/fit/verification) with different
levels of justification needed for
[sensitive and restricted scopes](https://developers.google.com/fit/datatypes.md.txt#authorization_scopes).