0

I am migrating from the deprecated GoogleApiClient for a wearOS watch face but I cannot get the daily steps count to work at all with the new interfaces. I am running nearly the exact code as the examples given on the developer website:

OnCreate in watchface engine:

GoogleSignInOptionsExtension fitnessOptions =
      FitnessOptions.builder()
          .addDataType(DataType.TYPE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
          .build();

    GoogleSignInAccount gsa = GoogleSignIn.getAccountForExtension(this, fitnessOptions);

mFitnessClient = Fitness.getHistoryClient(getApplicationContext(), gsa);

Recurrent Handler to poll for steps:

Task<DataSet> resultTask =  mFitnessClient.readDailyTotalFromLocalDevice(TYPE_STEP_COUNT_DELTA);
try
{
    DataSet totalSet = Tasks.await(resultTask);
    long total = totalSet.isEmpty() ? 0 : totalSet.getDataPoints().get(0).getValue(FIELD_STEPS).asInt();
} catch (Exception e) {
    ...
}

The results are always empty. Is this the correct way to do this? I noticed that you can no longer sign into the default account. My old code looks like this:

mClient = new GoogleApiClient.Builder(this)
        .addApi(Fitness.HISTORY_API)
        .useDefaultAccount()
        .addConnectionCallbacks(...)
        .build();
mClient.connect();

...

Fitness.HistoryApi.readDailyTotalFromLocalDevice(...)

and this worked fine. Any suggestions?

Jazzor
  • 21
  • 1
  • Have you checked the `resultTask` in `DataSet totalSet = Tasks.await(resultTask);` if it is throwing any value? – MαπμQμαπkγVπ.0 Sep 04 '18 at 09:44
  • Yes I have checked that. It throws 2 exceptions interrupted and another one, both of them are not thrown so I have encapsulated them into one catch for simplicity. – Jazzor Sep 05 '18 at 23:03

0 Answers0