android/fit-samples

Values that returned from History API is not the same with Google Fit App

codingjeremy opened this issue · 0 comments

Issue by panjiyudasetya
Wednesday Oct 31, 2018 at 05:00 GMT
Originally opened as googlearchive/android-fit#42


What happened

Step count value that I've been received from History API was different with step count values that has been displayed in Fit App. Even problem solving for different values between Fit History Api and Google Fit App has been mentioned here, sometimes this problem still occurred in certain device.

In my case, I was using :

  • Phone HTC One_E8 dual sim
  • Android version 6.0.1
  • Google Play services 14.3.66
Fit API Prober Fit App

As you can see that in Fit API prober, I got 3300 datapoint for today step count, meanwhile in Fit App, 2433 datapoint has been displayed. The margin is quite huge in this case.

What was expected

History API return same value with Google Fit App.

Code Snippets

As for addition, both approach are returning 3300 datapoint rather than 2433 datapoint.

History API today step count
        Fitness.getHistoryClient(mContext, GoogleSignIn.getLastSignedInAccount(mContext))
            .readDailyTotal(DataType.TYPE_STEP_COUNT_DELTA)
            .addOnSuccessListener(new OnSuccessListener<DataSet>() {
                @Override
                public void onSuccess(DataSet dataSet) {
                    int totalStepCount = extractHistoryFromDataSet(dataSet);
                    callback.onResult(totalStepCount);
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    callback.onError(e.getMessage());
                }
            });
History API through step count aggregation
DataSource getFitStepCountDataSource() {
        return new DataSource.Builder()
                .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
                .setType(DataSource.TYPE_DERIVED)
                .setStreamName("estimated_steps")
                .setAppPackageName("com.google.android.gms")
                .build();
}

Task<DataReadResponse> readHistory(long startTime, long endTime) {
        DataReadRequest request = new DataReadRequest.Builder()
            .aggregate(getFitStepCountDataSource(), DataType.AGGREGATE_STEP_COUNT_DELTA)
            .bucketByTime(1, TimeUnit.DAYS)
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .enableServerQueries()
            .build();
        return Fitness.getHistoryClient(mContext, GoogleSignIn.getLastSignedInAccount(mContext))
            .readData(request);
}