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?