适合无法获得每日步骤

时间:2018-05-08 08:37:10

标签: android google-fit

我很适合从fit api获取每日步骤。但它给了我错误时间段的步骤。

例如,我希望按照以下时间段提供步骤数据

06.05.2018 00.00 - 07.05.2018 00.00

07.05.2018 00.00 - 08.05.2018 00.00

08.05.2018 00.00 - 08.05.2017当前时间

但它给了我:

07.05.2018 17.13 - 08.05.2018 11.20所以我无法获得今天的步骤数据。有步骤数据(08.05.2018 00.00 - 08.05.2018当前时间)但我无法得到时间段问题的原因

我的代码有什么问题。这是代码块:

 final DataSource ds = new DataSource.Builder()
                                    .setAppPackageName("com.google.android.gms")
                                    .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
                                    .setType(DataSource.TYPE_DERIVED)
                                    .setStreamName("estimated_steps")
                                    .build();


                            DataReadRequest readRequest = new DataReadRequest.Builder()
                                    .aggregate(ds,DataType.AGGREGATE_STEP_COUNT_DELTA)
                                    .bucketByTime(1, TimeUnit.DAYS)
                                    .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                                    .build();

                            Fitness.getHistoryClient(MainActivity.activity, GoogleSignIn.getLastSignedInAccount(MainActivity.activity))
                                    .readData(readRequest)
                                    .addOnSuccessListener(new OnSuccessListener<DataReadResponse>()
                                    {
                                        @Override
                                        public void onSuccess(DataReadResponse dataReadResponse)
                                        {
                                            for (Bucket bucket : dataReadResponse.getBuckets())
                                            {
                                                for (DataSet dataSet : bucket.getDataSets())
                                                {


                                                    for (DataPoint dataPoint : dataSet.getDataPoints())
                                                    {

                                                        Crashlytics.log(Log.ASSERT, "Start:", Utils.formatDDMMYYYYHHmm(dataPoint.getStartTime(TimeUnit.MILLISECONDS)));
                                                        Crashlytics.log(Log.ASSERT, "End:", Utils.formatDDMMYYYYHHmm(dataPoint.getEndTime(TimeUnit.MILLISECONDS)));
                                                        Crashlytics.log(Log.ASSERT, "Steps: ", dataPoint.getValue(dataPoint.getDataType().getFields().get(0)).toString());
                                                        User.current().userFitnessData.addStepCountsFromDataPointFromFit(dataPoint);
                                                    }
                                                }
                                            }

                                            Crashlytics.log(Log.ASSERT, "Todays Steps", User.current().userFitnessData.getTodaysSteps() + "");

                                            // User.current().userFitnessData.logStepsTable();
                                            stepsDataReceivedCallBack.onStepsDataReceived();
                                            syncToServer(meResponse.body(), response.body(), lastLogDate);
                                        }
                                    });

0 个答案:

没有答案