Is there a way to read daily resting heart rate from the Google Fit API?

只愿长相守 提交于 2021-01-02 07:31:31

问题


The iOS Google Fit app shows Resting Heart Rate as one of it's metrics (I have not seen it in the Android Google Fit app, however). I would like to show Resting Heart Rate in an Android app using Google Fit Data. However, the Android Google Fit API does not seem to present this data.

I have tried a read request both by DataType.TYPE_HEART_RATE_BPM and by aggregating DataType.TYPE_HEART_RATE_BPM and DataType.AGGREGATE_HEART_RATE_SUMMARY as shown here:

DataReadRequest.Builder()
                    .aggregate(DataType.TYPE_HEART_RATE_BPM, DataType.AGGREGATE_HEART_RATE_SUMMARY)
                    .bucketByTime(1, TimeUnit.DAYS)
                    .enableServerQueries()
                    .setTimeRange(startDate.time, endDate.time, TimeUnit.MILLISECONDS)
                    .build()

The summary gives lowest, highest, and average for a particular time range, but not resting heart rate. Is there a way to get the calculated resting heart rate from the Google Fit Android API?


回答1:


I use the Google Fit API but with Python, so I am unsure if this helps.

I set the scope in the Google API console:

https://www.googleapis.com/auth/fitness.heart_rate.read

I then select this datasource to retrieve the resting heart rate (RHR) for that day (or time period):

derived:com.google.heart_rate.bpm:com.google.android.gms:resting_heart_rate<-merge_heart_rate_bpm

The JSON response is as follows, the RHR is shown in "fpval" key.

{
    "minStartTimeNs": "1606262400000000000",
    "maxEndTimeNs": "1606344504000000000",
    "dataSourceId": "derived:com.google.heart_rate.bpm:com.google.android.gms:resting_heart_rate<-merge_heart_rate_bpm",
    "point": [
        {
            "startTimeNanos": "1606320000000000000",
            "endTimeNanos": "1606320000000000000",
            "dataTypeName": "com.google.heart_rate.bpm",
            "originDataSourceId": "derived:com.google.heart_rate.bpm:com.google.android.gms:resting_heart_rate<-merge_heart_rate_bpm",
            "value": [
                {
                    "fpVal": 64.49201202392578,  <----- RHR
                    "mapVal": []
                }
            ],
            "modifiedTimeMillis": "1606323455964"
        }
    ]
}


来源:https://stackoverflow.com/questions/58714865/is-there-a-way-to-read-daily-resting-heart-rate-from-the-google-fit-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!