Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed BMR readings on Android #782

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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