android - 如何从 Google Fit 历史记录中获取心率值?

标签 android google-api google-play-services google-fit

我需要获得所有心率测量值,而不是我能够获得的最小值、最大值和平均值。

这是我用来读取我的 java 类的代码。

谢谢!

private void readDataFitnessHistory()
{
    // Setting a start and end date using a range of 1 week before this moment.
    Calendar cal = Calendar.getInstance();
    Date now = new Date();
    cal.setTime(now);
    long endTime = cal.getTimeInMillis();

    cal.add(Calendar.WEEK_OF_YEAR, -1);
    long startTime = cal.getTimeInMillis();

    java.text.DateFormat dateFormat = getDateInstance();
    Log.d(TAG, "Range Start: " + dateFormat.format(startTime));
    Log.d(TAG, "Range End: " + dateFormat.format(endTime));

    DataReadRequest readRequest = new DataReadRequest.Builder()
            // The data request can specify multiple data types to return, effectively
            // combining multiple data queries into one call.
            // In this example, it's very unlikely that the request is for several hundred
            // datapoints each consisting of a few steps and a timestamp.  The more likely
            // scenario is wanting to see how many steps were walked per day, for 7 days.
            .aggregate(DataType.TYPE_HEART_RATE_BPM, DataType.AGGREGATE_HEART_RATE_SUMMARY)
            // Analogous to a "Group By" in SQL, defines how data should be aggregated.
            // bucketByTime allows for a time span, whereas bucketBySession would allow
            // bucketing by "sessions", which would need to be defined in code.
            .bucketByTime(1, TimeUnit.DAYS)
            .enableServerQueries()
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .build();

    // Invoke the History API to fetch the data with the query and await the result of
    // the read request.
    DataReadResult dataReadResult =
            Fitness.HistoryApi.readData(mApiClient, readRequest).await(1, TimeUnit.MINUTES);
    DataSet dataSet = dataReadResult.getDataSet(DataType.TYPE_HEART_RATE_BPM);
    showDataSet(dataSet);
    displayBpmDataForToday();


}

响应:

History:    Type: com.google.heart_rate.summary
History:    Start: 22 sept. 2017 10:40:06
D/DBGPRUEBA History:    End: 22 sept. 2017 10:40:06
D/DBGPRUEBA History:    Field: average Value: 71.13179
D/DBGPRUEBA History:    Field: max Value: 86.0
D/DBGPRUEBA History:    Field: min Value: 55.0

最佳答案

我在回答我自己的问题。

为了获得使用 Google Fit Api 进行的读数的所有数据点,要构建的对象 DataRsult 如下:

final DataReadRequest readRequest = new DataReadRequest.Builder()
.read(DataType.TYPE_STEP_COUNT_DELTA)
.read(DataType.TYPE_HEART_RATE_BPM)
.enableServerQueries()
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();

它将返回指定范围内的所有数据点。

关于android - 如何从 Google Fit 历史记录中获取心率值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46425694/

相关文章:

android - ICS 中的 SimpleCursorAdapter

ruby - Google-api-ruby-client 翻译 API 示例

android - Google Play 游戏服务登录按钮吐出 "Unknown error"

android - Google APIs Java 客户端不适用于 PlayStore 构建

仅在某些手机上存在 Android 应用错误/错误

android - 在更新程序脚本中使用通配符删除文件

python - Google YouTube API v3 抛出 503 后端错误

c# - Google.Apis 共享访问和刷新 token

android - 如果应用程序被反编译,GoogleAuthUtils.getToken() 的安全性如何

android - 什么可能导致android中出现此错误?