Dipan Das
Dipan Das

Reputation: 11

how to fetch Heart Rate Googlefit?

Now I am implementing googlefit in my android application. I can not find any proper documentation for fetching heart rate. Please help me to fetch heart rate data from googlefit sdk/api.

Upvotes: 0

Views: 151

Answers (1)

BearDroid
BearDroid

Reputation: 583

if you're primarily relying on Fit's aggregation type called "Heart Points", then you can have this within your aggregate request body :

{
"aggregateBy": [
    {
        "dataTypeName": "com.google.heart_minutes",
        "dataSourceId": "derived:com.google.heart_minutes:com.google.android.gms:merge_heart_minutes"
    }
],
"bucketByTime": {
    "durationMillis": 86400000 //bucketed in a day
},
"startTimeMillis": //insert your start time in millis,
"endTimeMillis": //insert your end time in millis
}

But if you really want to pull raw Heart Rate datapoints, you can execute it using this body instead :

{
"aggregateBy": [
    {
        "dataTypeName": "com.google.heart_rate.bpm",
        "dataSourceId": "derived:com.google.heart_rate.bpm:com.google.android.gms:merge_heart_rate_bpm"
    }
],
"bucketByTime": {
    "durationMillis": 8640000 //bucketed in a day
},
"startTimeMillis": //insert your start time in millis,
"endTimeMillis": //insert your end time in millis 
}

I recommend that you familiarise yourself with the Fit system architecture, especially with querying what datasource are available for the types you would like to query.

Upvotes: 0

Related Questions