Google fit api returning empty bucket while fetching last week data

41 Views Asked by At

I am trying to fetch step count data of last week or last 7 days. I am getting the empty list of bucket which holds the data.

//Check how many steps were walked and recorded in the last 7 days
        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();

        DataReadResult dataReadResult = Fitness.HistoryApi.readData(mGoogleApiClient, readRequest).await(1, TimeUnit.MINUTES);

1

There are 1 best solutions below

0
Bugger On

the first you should check the fit app has data in that range date, and use same google account with your app. To enable querying the Google Fit server to fetch query results, in case the local store doesn't have data for the full requested time range.

DataReadRequest.Builder().enableServerQueries()

I'm using Fitness.getHistoryClient(params).readData() and pass the GoogleSignIn account.