如何知道步骤由传感器记录或由用户以编程方式从谷歌拟合输入

时间:2015-11-06 13:07:53

标签: android google-fit

我从此代码

获取谷歌适合的步骤
PendingResult<DataReadResult> pendingResult = Fitness.HistoryApi
            .readData(
                    fitnessClient,
                    new DataReadRequest.Builder()
                            .aggregate(DataType.TYPE_STEP_COUNT_DELTA,
                                    DataType.AGGREGATE_STEP_COUNT_DELTA)
                            .bucketByTime(1, TimeUnit.DAYS)
                            .setTimeRange(startTime, endTime,
                                    TimeUnit.MILLISECONDS).build());
    int steps = 0;
    DataReadResult dataReadResult = pendingResult.await();
    if (dataReadResult.getBuckets().size() > 0) {
        //Log.e("TAG", "Number of returned buckets of DataSets is: "
                //+ dataReadResult.getBuckets().size());
        for (Bucket bucket : dataReadResult.getBuckets()) {
            List<DataSet> dataSets = bucket.getDataSets();
            for (DataSet dataSet : dataSets) {
                for (DataPoint dp : dataSet.getDataPoints()) {
                    for (Field field : dp.getDataType().getFields()) {
                        steps += dp.getValue(field).asInt();
                    }
                }
            }
        }
    } else if (dataReadResult.getDataSets().size() > 0) {
        for (DataSet dataSet : dataReadResult.getDataSets()) {
            for (DataPoint dp : dataSet.getDataPoints()) {
                for (Field field : dp.getDataType().getFields()) {
                    steps += dp.getValue(field).asInt();
                }
            }
        }
    }
    return steps;

现在我的应用程序中有一个设置选项,该用户可以关闭健康工具包感应的步骤。如何实现这一功能?

1 个答案:

答案 0 :(得分:0)

您可以查看每个 DataPoint getOriginalDatasource ,然后查询数据源以获取流标识符。如果您获得 soft_step_counter ,则表示用户手动记录。