Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fitness.API removed in Google Play Services 7.0?

After upgrading to Google Play Services 7.0, my GoogleApiClient code for connecting to Google Fit no longer works: it says:

Error:(87, 21) error: no suitable method found for addApi(Void) method Builder.addApi(Api,O) is not applicable (cannot instantiate from arguments because actual and formal argument lists differ in length) method Builder.addApi(Api) is not applicable (actual argument Void cannot be converted to Api by method invocation conversion) where O is a type-variable: O extends HasOptions declared in method addApi(Api,O)

Where my code for building the GoogleApiClient is:

mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addApi(Fitness.API)
    .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();
like image 476
ianhanniballake Avatar asked Dec 19 '22 05:12

ianhanniballake


1 Answers

Per the Google Play services 7.0 blog post:

The previous Fitness.API that you passed into your GoogleApiClient has now been replaced with a number of APIs, matching the high level set of Google Fit Android APIs:

  • SENSORS_API to access raw sensor data via SensorsApi
  • RECORDING_API to record data via RecordingApi
  • HISTORY_API for inserting, deleting, or reading data via HistoryApi
  • SESSIONS_API for managing sessions via SessionsApi
  • BLE_API to interact with Bluetooth Low Energy devices via BleApi
  • CONFIG_API to access custom data types and settings for Google Fit via ConfigApi

Therefore you should update your GoogleApiClient to add all of the appropriate APIs you use. For example, if you use both the SensorsApi and the RecordingApi, your code should look like:

mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addApi(Fitness.SENSORS_API)
    .addApi(Fitness.REPORTING_API)
    .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();

Note: apps compiled against older versions of Google Play services will continue to work, but won't get the memory benefit that comes with the split APIs in Google Play services 7.0 as mentioned in the same blog post:

This change significantly reduces the memory requirement for Google Fit enabled apps running in the background. Like always, apps built on previous versions of Google Play services will continue to work, but we strongly suggest you rebuild your Google Fit enabled apps to take advantage of this change.

like image 102
ianhanniballake Avatar answered Dec 21 '22 19:12

ianhanniballake