【问题标题】:How to get Heart Rate values from Google Fit History?如何从 Google Fit History 中获取心率值?
【发布时间】:2017-09-26 11:47:43
【问题描述】:

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

这是我用来从我的 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

【问题讨论】:

  • TYPE_HEART_RATE_BPM(每分钟心跳次数)是否符合您的要求?
  • 如果是这样,但我需要的是在指示的时间范围内获得所有测量值,而不是在指示的时间范围内的最小值、最大值和平均值。
  • 我认为这还不可能。正如documentation 所述,您只能使用com.google.heart_rate.summary 数据类型来获取某个时间间隔内每分钟的平均、最大和最小节拍。
  • 您好,谢谢您的评论,我认为您是对的,但是我看到您可以通过数据立方体提取数据,但我不知道它的最小周期是多少您可以对该数据进行分组。(.bucketByTime(1, TimeUnit.HOURS))
  • 您好,谢谢您的评论,我认为您是对的,但是我看到您可以通过数据立方体提取数据,但我不知道它的最小周期是多少您可以对该数据进行分组。 (.bucketByTime(1, TimeUnit.HOURS)) 将是 1 小时的最大周期还是可以以分钟为单位设置? (.bucketByTime(10, TimeUnit.MINUTES) 我试过了,但它总是返回一个至少一小时间隔的桶。谢谢!

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


【解决方案1】:

我正在回答我自己的问题。

为了获取使用 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();

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

【讨论】:

  • 是否需要指定 .enableServerQueries() ?由于我是使用 google-fit 的新手,所以我想知道它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多