2017-09-26 76 views
0

我需要得到所有的心率測量值,而不是最小值,最大值和平均值,這正是我所能得到的。如何從Google健身歷史中獲取心率值?

這是我用於從我的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 
+0

TYPE_HEART_RATE_BPM(每分鐘跳動次數)沒有你想要的嗎? – Cadet

+0

如果是這樣,但我需要的是獲得指定時間範圍內的所有測量值,而不是指定時間範圍的最小值,最大值和平均值。 – ja12

+0

我不認爲這是不可能的。作爲[文件](https://developers.google.com/fit/android/data-types)說,你可以只使用'com.google.heart_rate.summary'數據類型,以獲得平均值,最大值和一段時間內每分鐘的最低節拍數。 – abielita

回答

0

我回答我的問題。

爲了獲得與谷歌飛度的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(); 

這將返回指定範圍內的所有數據點。