Skip to content

Commit

Permalink
feat: exposed bmr readings on android
Browse files Browse the repository at this point in the history
  • Loading branch information
rshams-dius committed Jul 28, 2023
1 parent f1fc4d3 commit d407f95
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/health/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Note that for Android, the target phone **needs** to have [Google Fit](https://w
| **Data Type** | **Unit** | **iOS** | **Android (Google Fit)** | **Android (Health Connect)** | **Comments** |
| --------------------------- | ----------------------- | ------- | ------------------------ | ---------------------------- | -------------------------------------- |
| ACTIVE_ENERGY_BURNED | CALORIES | yes | yes | yes | |
| BASAL_ENERGY_BURNED | CALORIES | yes | | | |
| BASAL_ENERGY_BURNED | CALORIES | yes | yes | | |
| BLOOD_GLUCOSE | MILLIGRAM_PER_DECILITER | yes | yes | yes | |
| BLOOD_OXYGEN | PERCENTAGE | yes | yes | yes | |
| BLOOD_PRESSURE_DIASTOLIC | MILLIMETER_OF_MERCURY | yes | yes | yes | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
private var STEPS = "STEPS"
private var AGGREGATE_STEP_COUNT = "AGGREGATE_STEP_COUNT"
private var ACTIVE_ENERGY_BURNED = "ACTIVE_ENERGY_BURNED"
private var BASAL_ENERGY_BURNED = "BASAL_ENERGY_BURNED"
private var HEART_RATE = "HEART_RATE"
private var BODY_TEMPERATURE = "BODY_TEMPERATURE"
private var BLOOD_PRESSURE_SYSTOLIC = "BLOOD_PRESSURE_SYSTOLIC"
Expand Down Expand Up @@ -418,6 +419,7 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
STEPS -> DataType.TYPE_STEP_COUNT_DELTA
AGGREGATE_STEP_COUNT -> DataType.AGGREGATE_STEP_COUNT_DELTA
ACTIVE_ENERGY_BURNED -> DataType.TYPE_CALORIES_EXPENDED
BASAL_ENERGY_BURNED -> DataType.TYPE_BASAL_METABOLIC_RATE
HEART_RATE -> DataType.TYPE_HEART_RATE_BPM
BODY_TEMPERATURE -> HealthDataTypes.TYPE_BODY_TEMPERATURE
BLOOD_PRESSURE_SYSTOLIC -> HealthDataTypes.TYPE_BLOOD_PRESSURE
Expand All @@ -442,6 +444,7 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
WEIGHT -> Field.FIELD_WEIGHT
STEPS -> Field.FIELD_STEPS
ACTIVE_ENERGY_BURNED -> Field.FIELD_CALORIES
BASAL_ENERGY_BURNED -> Field.FIELD_CALORIES
HEART_RATE -> Field.FIELD_BPM
BODY_TEMPERATURE -> HealthFields.FIELD_BODY_TEMPERATURE
BLOOD_PRESSURE_SYSTOLIC -> HealthFields.FIELD_BLOOD_PRESSURE_SYSTOLIC
Expand Down Expand Up @@ -944,6 +947,31 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
),
)
}
/*
BMR is not available to be retrieved for every day (although it is reflected in Google Fit energy calcs for every single day)
Thus, a specific case is defined below for handling BMR, with "1" provided as startDate to the setTimeRange method.
A limit of "1" is also set through setLimit, to only get the latest value.
Note:
According to Google's documentation, since "the recorded BMR is instantaneous, the start time should not be set.".
However, startTime is oddly enough a required property.
*/
DataType.TYPE_BASAL_METABOLIC_RATE -> {
Fitness.getHistoryClient(activity!!.applicationContext, googleSignInAccount)
.readData(
DataReadRequest.Builder()
.read(dataType)
.setTimeRange(1, endTime, TimeUnit.MILLISECONDS)
.setLimit(1)
.build()
)
.addOnSuccessListener(threadPoolExecutor!!, dataHandler(dataType, field, result))
.addOnFailureListener(
errHandler(
result,
"There was an error getting BMR data!"
),
)
}
else -> {
Fitness.getHistoryClient(context!!.applicationContext, googleSignInAccount)
.readData(
Expand Down
1 change: 1 addition & 0 deletions packages/health/lib/src/data_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const List<HealthDataType> _dataTypeKeysIOS = [
/// List of data types available on Android
const List<HealthDataType> _dataTypeKeysAndroid = [
HealthDataType.ACTIVE_ENERGY_BURNED,
HealthDataType.BASAL_ENERGY_BURNED,
HealthDataType.BLOOD_GLUCOSE,
HealthDataType.BLOOD_OXYGEN,
HealthDataType.BLOOD_PRESSURE_DIASTOLIC,
Expand Down

0 comments on commit d407f95

Please sign in to comment.