Google Fit的步骤

时间:2017-12-07 20:09:45

标签: android google-fit

我是android的新手。我试图恢复上个月每天采取的步骤。当我调用该方法时,它只返回17个结果。我做错了什么?

public void stepsThisMonth() {
    mClient.connect();
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 59);

    long endTime = cal.getTimeInMillis();
    cal.add(Calendar.DAY_OF_YEAR, -30);
    long startTime = cal.getTimeInMillis();

    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();

    PendingResult<DataReadResult> result = Fitness.HistoryApi.readData(mClient, readRequest);
    result.setResultCallback(new ResultCallback<DataReadResult>() {
        @Override
        public void onResult(@NonNull DataReadResult dataReadResult) {
            int total = 0;
            ArrayList<String> array1 = new ArrayList<>();
            for (Bucket bucket : dataReadResult.getBuckets()) {
                List<DataSet> dataSetx = bucket.getDataSets();
                for (DataSet dataSet : dataSetx) {
                    if (dataSet.getDataType().getName().equals("com.google.step_count.delta")) {
                        if (dataSet.getDataPoints().size() > 0) {
                            array1.add(String.valueOf(dataSet.getDataPoints().get(0).getValue(Field.FIELD_STEPS).asInt()));
                       dataSet.getDataPoints().get(0).getValue(Field.FIELD_STEPS).asInt();
                        }
                    }
                }
            }
            saveUpdateArray(array1, "monthSteps");
        }
    });
}

0 个答案:

没有答案