Google Fit provides a set of fitness 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.
For more information about inserting data points, see Work with the Fitness History.
Data types
Google Fit features the following data types:
- Public data types
- Standard data types provided by the platform, like com.google.step_count.delta. Any app can
read and write data of these types, with some limited exceptions.
For more information, see Public Data Types. - Private custom data types
- Custom data types defined by an 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. - Restricted data types
- Google Fit restricts write access for the data types in
HealthDataTypes
to only certain developers.
For more information, see Restricted Data Types.
Public data types
Google Fit defines public data types for instantaneous readings and data types for aggregate data.
Data types for instantaneous readings
These data types are defined as public fields of the
DataType
class. Their field names start with the TYPE_
prefix.
Data Type Name | Description | Permission | Fields (Format—Unit) |
---|---|---|---|
com.google.active_minutes |
The user's Move Minutes. | Activity |
duration (int —minutes) |
com.google.activity.sample |
Instantaneous sample of the current activity. | Activity |
activity (int —enum)confidence ( float —percent) |
com.google.activity.segment |
Continuous time interval of a single activity. | Activity |
activity (int —enum) |
com.google.calories.expended |
Total calories expended over a time interval. | Activity |
calories (float —kcal) |
com.google.cycling |
Instantaneous pedaling rate in crank revolutions per minute. | Activity |
rpm (float —rpm) |
com.google.cycling |
Instantaneous wheel speed. | Location |
rpm (float —rpm) |
com.google.distance.delta |
Distance covered since the last reading. | Location |
distance (float —meters) |
com.google.heart_points |
The user's Heart Points. | Activity |
intensity (float —heart points) |
com.google.heart_rate.bpm |
Heart rate in beats per minute. | Body |
bpm (float —bpm) |
com.google.height |
The user's height, in meters. | Body |
height (float —meters) |
com.google.nutrition |
Food item information | Nutrition |
nutrients (Map<String, float> —calories/grams/IU)meal_type ( int —enum)food_item ( String —n/a) |
com.google.power.sample |
Instantaneous power generated while performing an activity. | Activity |
watts (float —watts) |
com.google.speed |
Instantaneous speed over ground. | Location |
speed (float —m/s) |
com.google.step_count.cadence |
Instantaneous cadence in steps per minute. | Activity |
rpm (float —steps/min) |
com.google.step_count.delta |
Number of new steps since the last reading. | Activity |
steps (int —count) |
com.google.weight |
The user's weight. | Body |
weight (float —kg) |
com.google.activity.exercise |
A user's continuous workout routine. | Activity |
exercise (int —enum)repetitions ( int —count)resistance type ( int —enum)resistance ( float —kg)duration ( int —milliseconds) |
Set data point values
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 the data from the fitness history with the History API.
Data types for aggregate data
These data types are defined as public fields of the
DataType
class. Their field names start with the AGGREGATE_
prefix.
Data Type Name | Description | Permission | Fields (Format—Unit) |
---|---|---|---|
com.google.activity.summary |
Total time and number of segments in a particular activity for a time interval. | Activity |
activity (int —enum)duration ( int —ms)num_segments ( int —count) |
com.google.heart_rate.summary |
Average, maximum, and minimum beats per minute for a time interval. | Body |
average (float —bpm)max ( float —bpm)min ( float —bpm) |
com.google.nutrition.summary |
User's nutrition intake during a time interval. | Nutrition |
nutrients (Map<String, float> —calories/grams/IU)meal_type ( int —enum)food_item ( String —n/a) |
com.google.power.summary |
Average, maximum, and minimum power generated while performing an activity. | Activity |
average (float —watts)max ( float —watts)min ( float —watts) |
com.google.speed.summary |
Average, maximum, and minimum speed over ground over a time interval. | Location |
average (float —m/s)max ( float —m/s)min ( float —m/s) |
com.google.weight.summary |
Average, maximum, and minimum weight over a time interval. | Body |
average (float —kg)max ( float —kg)min ( float —kg) |
Using fitness data types on Android
On Android, the fitness 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 fitness data, use the Recording API to create a subscription for each data type you want to record.
- To read fitness data, use the History API to submit a read request for each data type.
- To insert data into the fitness history, use the History API to submit an insert request for each data type.
- To create sessions, use the Sessions API to insert or record fitness data with session metadata.
Exceptions
Whilst any application can write data to a public data type, there are certain data types which can only be read by the application that wrote the data.
Data Type Name | Description | Fields (Format—Unit) |
---|---|---|
com.google.location.sample |
The user's current location. |
latitude (float —degrees)longitude ( float —degrees)accuracy ( float —meters)altitude ( float —meters) |
com.google.location.bounding_box |
A bounding box for the user's location over a time interval. |
low_latitude (float —degrees)low_longitude ( float —degrees)high_latitude ( float —degrees)high_longitude ( float —degrees) |
Custom data types
Google Fit enables you to create custom data types for your app and to use them to store fitness data. When you create custom data types, ensure that:
- Google Fit does not already provide a similar data type
- The data type name is clear
- The data type name accurately represents the underlying data
- The prefix of the data type name matches your app's package name
Create a custom data type
To create a custom data type for the first time, use the
ConfigClient.createCustomDataType
method:
// 1. Build a request to create a new data type DataTypeCreateRequest request = new DataTypeCreateRequest.Builder() // The prefix of your data type name must match your app's package name .setName("com.app.custom_data_type") // Add some custom fields, both int and float .addField("field1", Field.FORMAT_INT32) .addField("field2", Field.FORMAT_FLOAT) // Add some common fields .addField(Field.FIELD_ACTIVITY) .build(); // 2. Invoke the Config API with: // - The Google API client object // - The create data type request PendingResult<DataTypeResult> pendingResult = ConfigApi.createCustomDataType(mClient, request); // 3. Check the result asynchronously // (The result may not be immediately available) pendingResult.setResultCallback( new ResultCallback<DataTypeResult>() { @Override public void onResult(DataTypeResult dataTypeResult) { // Retrieve the created data type DataType customType = dataTypeResult.getDataType(); // Use this custom data type to insert data in your app // (see other examples) ... } } );
Retrieve your custom data types
To access a custom data type, use the ConfigClient.readDataType
method:
// 1. Invoke the Config API with: // - The Google API client object // - The custom data type name PendingResult<DataTypeResult> pendingResult = ConfigApi.readDataType(mClient, "com.app.custom_data_type"); // 2. Check the result asynchronously // (The result may not be immediately available) pendingResult.setResultCallback( new ResultCallback<DataTypeResult>() { @Override public void onResult(DataTypeResult dataTypeResult) { // Retrieve the custom data type DataType customType = dataTypeResult.getDataType(); // Use this custom data type to insert data in your app // (see other examples) ... } } );
Restricted data types
Because health data is potentially sensitive, Google Fit restricts write access
for the data types in HealthDataTypes
to only certain developers. Apps need user permission to read and write data of
a restricted type. Any application can read fitness data of a restricted data
type, but only Google-approved applications can write data of this type.