从谷歌健身中读取重量

时间:2017-05-09 01:10:52

标签: android google-fit

我无法从Google健身中读取重量。 当我向Google Fit请求重量时,我只获得重量字段(重量)的名称,但DataPoints大小为0.有什么问题?

代码:

DataReadRequest dataReadRequest = queryFitnessData();

DataReadResult dataReadResult = Fitness.HistoryApi.readData(getApiClient(), dataReadRequest)
                .await(1000, TimeUnit.MILLISECONDS);
////////
private static DataReadRequest queryFitnessData() {
    Calendar calendar = Calendar.getInstance();
    Date date = new Date();
    calendar.setTime(date);
    long endTime = calendar.getTimeInMillis();
    calendar.add(Calendar.YEAR, -1);
    long startTime = calendar.getTimeInMillis();

    DataReadRequest dataReadRequest = new DataReadRequest.Builder()
            .read(DataType.TYPE_WEIGHT)
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .build();

    return dataReadRequest;
}

1 个答案:

答案 0 :(得分:2)

您是否在指定的时间范围内添加了重量。可以尝试

DataReadRequest dataReadRequest = new DataReadRequest.Builder()
            .read(DataType.TYPE_WEIGHT)
            .setTimeRange(1, endTime, TimeUnit.MILLISECONDS)
            .setLimit(1)
            .build();