User authorization is required before your application can read or write any fitness sensor data. User authorization is a two-step process. Step one is the registration of your application with the Google developer console, which is done outside your application. Step two is getting authorization from the user by using relevant scopes inside your application.
Every application that needs to access fitness sensor data needs to register with the Google developer console. The followings steps explain the registration process:
After completing the one-time registration with Google developer console, the user consent has to be taken inside the application. As a first step, we have to select the required scopes and then we have to connect to Google Play Services. Depending on the number of scopes set, Google Play Services will prompt the user with an authorization dialog showing the required permissions. Once the user gives consent, your applications can access the Fitness APIs. The implementation details are discussed in the fitness tracker application, in the second half of the chapter. The following is a screenshot of the authorization dialog, showing the required permissions for the device:
Scopes are strings that determine what kinds of fitness data an app can access and also define the level of access to this data. Scopes belong to a particular permissions group. The following table lists the different types of scope, their type of access, their data types, and the permissions group that they belong to.
Permission Group |
Scopes |
Type of Access |
Data Types |
Activity |
FITNESS_ACTIVITY_READ |
Read |
com.google.activity.sample |
com.google.activity.segment | |||
com.google.activity.summary | |||
com.google.calories.consumed (deprecated) | |||
com.google.calories.expended | |||
FITNESS_ACTIVITY_READ_WRITE |
Read and write |
com.google.cycling.pedaling.cadence | |
com.google.power.sample | |||
com.google.step_count.cadence | |||
com.google.step_count.delta | |||
com.google.activity.exercise | |||
Body |
FITNESS_BODY_READ |
Read |
com.google.heart_rate.bpm |
com.google.heart_rate.summary | |||
FITNESS_BODY_READ_WRITE |
Read and write |
com.google.height | |
com.google.weight | |||
com.google.weight.summary | |||
Location |
FITNESS_LOCATION_READ
|
Read |
com.google.cycling.wheel_revolution.cumulative |
com.google.cycling.wheel.revolutions | |||
com.google.distance.delta | |||
FITNESS_LOCATION_READ_WRITE |
Read and write |
com.google.location.sample | |
com.google.location.bounding_box | |||
com.google.speed | |||
com.google.speed.summary | |||
Nutrition |
FITNESS_NUTRITION_READ |
Read |
com.google.nutrition.item |
FITNESS_NUTRITION_READ_WRITE |
Read and write |
com.google.nutrition.summary |
If your application is using any of the DataTypes
that belong to either the Location or Body permission groups shown in the preceding table, your application needs to have the following permissions:
DataType
that belong to either the Location or Body permission groups, then it needs to have ACCESS_FINE_LOCATION
for Location-based data types and BODY_SENSORS
for body-based data types.DataType
that belong to either the Location or Body permission groups and is compiled with SDK version 23 (Marshmallow) or above, then your application needs to get run time permission for ACCESS_FINE_LOCATION
and BODY_SENSORS
.The installation time permissions in AndroidManifest.xml
and the run time permissions are different from the user authorization discussed in the previous section.