how to get past 1 month data?
yoshimaa opened this issue · comments
I want to know how to get google fit past 30days data.
I use this way, 'aggregate, DataType.AGGREGATE_STEP_COUNT_DELTA',and 'bucketByTime(1, TimeUnit.DAYS)'
but I can not get whole 30days, only get 15 or 16days.
long aDayMills = 1000 * 60 * 60 * 24;
DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setType(DataSource.TYPE_DERIVED)
.setStreamName("estimated_steps")
.setAppPackageName("com.google.android.gms")
.build();
for (int i = 1; i < 30; i++) {
long start = start - (aDayMills * i);
long end = start - (aDayMills * (i - 1)) - 1;
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
.aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
.aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
.aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(start, end, TimeUnit.MILLISECONDS)
.build();
Fitness.HistoryApi.readData(googleApiClient, readRequest).setResultCallback(new com.google.android.gms.common.api.ResultCallback<DataReadResult>() {
@Override
public void onResult(@NonNull DataReadResult dataReadResult) {
com.google.android.gms.common.api.Status status = dataReadResult.getStatus();
if (status.isSuccess()) {
printData(dataReadResult);
} else {
Log.d(TAG, "statusCode:" + status.getStatusCode() + ",message:" + status.getStatusMessage());
}
}
});
}
I cannot get correct data if get whole 30days data by one request.
please tell me how to get whole past 30days fit data.
thanks.