react-native-google-fit
A React Native bridge module for interacting with Google Fit
Quick Links
USAGE
-
import GoogleFit, { Scopes } from 'react-native-google-fit'
-
Authorize:
// The list of available scopes inside of src/scopes.js fileconst options =scopes:ScopesFITNESS_ACTIVITY_READ_WRITEScopesFITNESS_BODY_READ_WRITEGoogleFit// ...// Call when authorizedGoogleFit;Alternatively you can use event listeners (deprecated)
GoogleFitGoogleFit -
Retrieve Steps For Period
const options =startDate: "2017-01-01T00:00:17.971Z" // required ISO8601TimestampendDate: // required ISO8601Timestamp;GoogleFitResponse:
source: "com.google.android.gms:estimated_steps" steps:"date":"2019-06-29""value":2328"date":"2019-06-30""value":8010source: "com.google.android.gms:merge_step_deltas" steps:"date":"2019-06-29""value":2328"date":"2019-06-30""value":8010source: "com.xiaomi.hm.health" steps:; -
Retrieve Weights
const opt =unit: "pound" // required; default 'kg'startDate: "2017-01-01T00:00:17.971Z" // requiredendDate: // requiredascending: false // optional; default false;GoogleFit;Response:
"value":72"endDate":"2019-06-29T15:02:23.413Z""startDate":"2019-06-29T15:02:23.413Z""day":"Sat""value":724000015258789"endDate":"2019-07-26T08:06:42.903Z""startDate":"2019-07-26T08:06:42.903Z""day":"Fri" -
Retrieve Heights
const opt =startDate: "2017-01-01T00:00:17.971Z" // requiredendDate: // required;GoogleFit;Response:
"value":17699999809265137"endDate":"2019-06-29T15:02:23.409Z""startDate":"2019-06-29T15:02:23.409Z""day":"Sat" -
Save Weights
const opt =value: 200date:unit: "pound";GoogleFit; -
Blood pressure and Heart rate methods (since version 0.8)
const options =startDate: "2017-01-01T00:00:17.971Z" // requiredendDate: // requiredconst callback = {console};GoogleFitGoogleFitResponse:
// heart rate"value":80"endDate":"2019-07-26T10:19:21.348Z""startDate":"2019-07-26T10:19:21.348Z""day":"Fri"// blood pressure"value":120"value2":80"endDate":"2019-07-26T08:39:28.493Z""startDate":"1970-01-01T00:00:00.000Z""day":"Thu" -
Get all activities
let options =startDate: 2018 9 17 // simply outputs the number of milliseconds since the Unix EpochendDate: 2018 9 18;GoogleFit;Response:
sourceName: 'Android'device: 'Android'sourceId: 'com.google.android.gms'calories: 764189208984375quantity: 6end: 1539774300992tracked: trueactivityName: 'still'start: 1539727200000sourceName: 'Android'device: 'Android'sourceId: 'com.google.android.gms'calories: 10351096153259277quantity: 138end: 1539774486088tracked: truedistance: 8809545135498047activityName: 'walking'Where:
sourceName = device - 'Android' or 'Android Wear' string sourceId - return a value of dataSource.getAppPackageName(). For more info see: https://developers.google.com/fit/android/data-attribution start/end - timestamps of activity in format of milliseconds since the Unix Epoch tracked - bool flag, is this activity was entered by user or tracked by device. Detected by checking milliseconds of start/end timestamps. Since when user log activity in googleFit they can't set milliseconds distance(opt) - A distance in meters. activityName - string, equivalent one of these https://developers.google.com/fit/rest/v1/reference/activity-types calories(opt) - double value of burned Calories in kcal. quantity(opt) - equivalent of steps number
Note that optional parametrs are not presented in all activities - only where google fit return some results for this field. Like no distance for still activity.
-
Retrieve Calories For Period
const opt =startDate: "2017-01-01T00:00:17.971Z" // requiredendDate: // requiredbasalCalculation: true // optional, to calculate or not basalAVG over the week;GoogleFit;Response:
"calorie":1721948974609375"endDate":"2019-06-27T15:13:27.000Z""startDate":"2019-06-27T15:02:23.409Z""day":"Thu""calorie":159825"endDate":"2019-06-28T15:13:27.000Z""startDate":"2019-06-27T15:13:27.000Z""day":"Thu" -
Retrieve Distance For Period:
const opt =startDate: "2017-01-01T00:00:17.971Z" // requiredendDate: // required;GoogleFit;Response:
"distance":2254958251953125"endDate":"2019-06-30T15:45:32.987Z""startDate":"2019-06-29T16:57:01.047Z""day":"Sat""distance":3020439453125"endDate":"2019-07-01T13:08:31.332Z""startDate":"2019-06-30T16:58:44.818Z""day":"Sun" -
Other methods:
; // On Step Changed Event; // Put into componentWillUnmount() method to prevent leaks; // Checks is GoogleFit available for current account / installed on device; // Checks is permissions granted; // method to delete weights by options (same as in save weights); //method to open google fit app;;;; // Closes the connection to Google Play services.
PLANS / TODO
- code refactoring
- optimization
Copyright (c) 2017-present, Stanislav Doskalenko doskalenko.s@gmail.com
Based on Asim Malik android source code, copyright (c) 2015, thanks mate!