1

I am trying to send history of one week Calories burnt data using History_API. My code is like this -

// Connection Establishment
DataReadRequest readRequest = new DataReadRequest.Builder()
                .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
                .bucketByTime(1, TimeUnit.DAYS)
                .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                .build();
Fitness.HistoryApi.readData(mClient, readRequest).setResultCallback(new ResultCallback<DataReadResult>() {

}

I am getting this error "GoogleApiClient is not configured to use Fitness.API required for this call." Any idea why?

Vinay K L
  • 91
  • 1
  • 1
  • 8

1 Answers1

3

You need to add the Fitness.SENSORS_API when you initialize the mClient.

The code will look something like this:

mClient = new GoogleApiClient.Builder(this)
                .addApi(Fitness.SENSORS_API)
                .build();

You can get more info here: https://developers.google.com/android/reference/com/google/android/gms/fitness/Fitness

jonathanrz
  • 4,206
  • 6
  • 35
  • 58
  • 1
    if (mClient == null) { mClient = new GoogleApiClient.Builder(this) .addApi(Fitness.SENSORS_API) .addScope(new Scope(Scopes.FITNESS_LOCATION_READ)) .addConnectionCallbacks( new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle bundle) { MyCode(); } – Vinay K L Nov 26 '16 at 20:40