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

Data types

Google Fit provides a set of health and wellness data types under the com.google namespace.

Data types define the format of the values inside data points. A data point can represent:

  • An instantaneous reading or observation
  • An aggregate with statistics over a time interval

Google Fit defines data types for instantaneous observations and data types for aggregate data. Data points consist of values for the fields of a data type and timestamp information. Points that represent instantaneous observations include a timestamp, and points of an aggregate data type also include the start time for the interval.

Google Fit also lets you define new data types.

Data type groups

Google Fit has these data types:

Public data types
Standard data types provided by the platform have the 'com.google' prefix. For example, com.google.step_count.delta. These data types capture instant readings for health and wellness data, including fitness activity, sleep and nutrition. Any app can request the relevant permissions to read and write to these data types, except for a few location data types which can only be read by the app that wrote them.

For more information, see:

Health data types
Data types provided by the platform that have restricted access due to potentially sensitive data. For more information, see Health data types.
Aggregate data types
Data types to read health and wellness information aggregated by time or activity type. For more information, see Aggregate data types.
Private custom data types
Custom data types defined by a specific app. Only the app that defines the data type can read and write data of this type. For more information, see Custom data types.

Using data types

Android

On Android, data types are defined as public fields of the DataType class. How you invoke the Fitness APIs with the data type depends on what you want to accomplish:

  • To record data, use the Recording API to create a subscription for each data type you want to record.
  • To read data, use the History API to submit a read request for each data type.
  • To insert historical data from the past, use the History API to submit an insert request for each data type.
  • To create sessions, use the Sessions API to insert or record data with session metadata.

To create data points for an instaneous DataType object, assign values with the correct format. The following example shows you how to assign the food item as a string, the meal type as a constant from the Field class, and nutrient contents as mapped float values by calling the setKeyValue() method.

DataSource nutritionSource = new DataSource.Builder()
        .setDataType(DataType.TYPE_NUTRITION)
        ...
        .build();

Map<String, Float> nutrients = new HashMap<>();
nutrients.put(Field.NUTRIENT_TOTAL_FAT, 0.4f);
nutrients.put(Field.NUTRIENT_SODIUM, 1f);
nutrients.put(Field.NUTRIENT_POTASSIUM, 422f);
DataPoint banana =
    DataPoint.builder(nutritionSource)
        .setTimestamp(now.getMillis(), TimeUnit.MILLISECONDS)
        .setField(Field.FIELD_FOOD_ITEM, "banana")
        .setField(Field.FIELD_MEAL_TYPE, Field.MEAL_TYPE_SNACK)
        .setField(Field.FIELD_NUTRIENTS, nutrients)
        .build();

After setting data points in your app, you can insert, read, or delete historical data with the History API.

REST

The dataSources resource includes the data type (and a list of its fields) for each data source. You can specify one of these data types when you create data sources, and you can obtain the name of the data type and a list of its fields when you retrieve a data source from the fitness store.

For example, a data source representation specifies its data type as follows:

{
"dataStreamId": "exampleDataSourceId",
...
"dataType": {
  "name": "com.google.step_count.delta"
},
...
}

Authorization scopes

Authorization scopes cover the permissions your app requests users to authorize to read and write data. Before your app can write or read data types, you need to request verification based on the scopes relevant to those data types. Read through the data types pages linked above to understand which scopes different data types come under.

For example, if your app needs to read and write writing blood pressure, it needs to declare it's doing both read and write and request both scopes. If it's only writing blood pressure data to the Google Fit platform, it only needs to request the write scope.

As a general rule, choose the most narrowly focused scope possible. Avoid requesting scopes that your app does not actually need. Users more readily grant access to limited, clearly described scopes.

Use this table to check if the scopes your app needs access to are sensitive or restricted (which determines the verification steps you'll need to follow):

Scope Description Category
https://www.googleapis.com/auth/fitness.activity.read Read activity data from the Google Fit platform. Restricted
https://www.googleapis.com/auth/fitness.activity.write Write activity data to the Google Fit platform Sensitive
https://www.googleapis.com/auth/fitness.blood_glucose.read Read blood glucose data from the Google Fit platform. Restricted
https://www.googleapis.com/auth/fitness.blood_glucose.write Write blood glucose data to the Google Fit platform. Sensitive
https://www.googleapis.com/auth/fitness.blood_pressure.read Read blood pressure data from the Google Fit platform. Restricted
https://www.googleapis.com/auth/fitness.blood_pressure.write Write blood pressure data to the Google Fit platform. Sensitive
https://www.googleapis.com/auth/fitness.body.read Read body measurement data (height, weight, body fat percentage) from the Google Fit platform. Restricted
https://www.googleapis.com/auth/fitness.body.write Write body measurement data to the Google Fit platform. Sensitive
https://www.googleapis.com/auth/fitness.body_temperature.read Read body temperature data from the Google Fit platform. Restricted
https://www.googleapis.com/auth/fitness.body_temperature.write Write body temperature data to the Google Fit platform. Sensitive
https://www.googleapis.com/auth/fitness.heart_rate.read Read heart rate data from the Google Fit platform. Restricted
https://www.googleapis.com/auth/fitness.heart_rate.write Write heart rate data to the Google Fit platform. Sensitive
https://www.googleapis.com/auth/fitness.location.read Read location data from the Google Fit platform. Restricted
https://www.googleapis.com/auth/fitness.location.write Write location data to the Google Fit platform. Sensitive
https://www.googleapis.com/auth/fitness.nutrition.read Read nutrition data from the Google Fit platform. Restricted
https://www.googleapis.com/auth/fitness.nutrition.write Write nutrition data to the Google Fit platform. Sensitive
https://www.googleapis.com/auth/fitness.oxygen_saturation.read Read oxygen saturation data from the Google Fit platform. Restricted
https://www.googleapis.com/auth/fitness.oxygen_saturation.write Write oxygen saturation data to the Google Fit platform. Sensitive
https://www.googleapis.com/auth/fitness.reproductive_health.read Read reproductive health data from the Google Fit platform. Restricted
https://www.googleapis.com/auth/fitness.reproductive_health.write Write reproductive health data to the Google Fit platform. Sensitive
https://www.googleapis.com/auth/fitness.sleep.read Read sleep data from the Google Fit platform. Restricted
https://www.googleapis.com/auth/fitness.sleep.write Write sleep data to the Google Fit platform. Sensitive