-
Notifications
You must be signed in to change notification settings - Fork 690
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
Attempt to fix Health Connect on Android 14 #834
Changes from all commits
543edbc
3668d52
cd71d0f
a9a0144
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,14 +160,14 @@ class _HealthAppState extends State<HealthApp> { | |
totalDistance: 2430, | ||
totalEnergyBurned: 400); | ||
success &= await health.writeBloodPressure(90, 80, earlier, now); | ||
success &= await health.writeHealthData( | ||
0.0, HealthDataType.SLEEP_REM, earlier, now); | ||
success &= await health.writeHealthData( | ||
0.0, HealthDataType.SLEEP_ASLEEP, earlier, now); | ||
success &= await health.writeHealthData( | ||
0.0, HealthDataType.SLEEP_AWAKE, earlier, now); | ||
success &= await health.writeHealthData( | ||
0.0, HealthDataType.SLEEP_DEEP, earlier, now); | ||
// success &= await health.writeHealthData( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these changes relevant to the PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah for some reason adding the sleep records is failing stating that it is an unsupported type. Although it is working on Android 13 and below. |
||
// 0.0, HealthDataType.SLEEP_REM, earlier, now); | ||
// success &= await health.writeHealthData( | ||
// 0.0, HealthDataType.SLEEP_ASLEEP, earlier, now); | ||
// success &= await health.writeHealthData( | ||
// 0.0, HealthDataType.SLEEP_AWAKE, earlier, now); | ||
// success &= await health.writeHealthData( | ||
// 0.0, HealthDataType.SLEEP_DEEP, earlier, now); | ||
|
||
success &= await health.writeMeal( | ||
earlier, now, 1000, 50, 25, 50, "Banana", MealType.SNACK); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,12 +69,12 @@ const List<HealthDataType> dataTypesAndroid = [ | |
// HealthDataType.MOVE_MINUTES, // TODO: Find alternative for Health Connect | ||
HealthDataType.DISTANCE_DELTA, | ||
HealthDataType.RESPIRATORY_RATE, | ||
HealthDataType.SLEEP_AWAKE, | ||
HealthDataType.SLEEP_ASLEEP, | ||
HealthDataType.SLEEP_LIGHT, | ||
HealthDataType.SLEEP_DEEP, | ||
HealthDataType.SLEEP_REM, | ||
HealthDataType.SLEEP_SESSION, | ||
// HealthDataType.SLEEP_AWAKE, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these changes relevant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fetching the SLEEP data is crashing the app with the same error as writing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked out this PR, uncommented the SLEEP lines, and i can read sleep data without a crash. I am running Android 14. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eliasteeny could you please double check if this error still occurs on your device and if so, tell us your OS version and setup? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got a closer look. I did not have a wearable so was reading only sleep session data (time asleep, one data point) and that worked fine. I get the crash now that i have a wearable and i try to read the stages. The issue seems to be that SleepStageRecord object no longer exists in Android 14. Instead there is a list in the SleepSessionRecord. You can see this sample code in https://developer.android.com/health-and-fitness/guides/health-connect/develop/sessions suspend fun readSleepSessions( The convertRecord function returns a single record and now it should return many, not sure how to handle this with the way it works now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a pull request on your fork @eliasteeny. I tested it on Android 13 and Android 14, both were able to pull both SLEEP_SESSION (total sleep time only) and individual sleep stages. I did not test writing though, i don't have an app that would do that. |
||
// HealthDataType.SLEEP_ASLEEP, | ||
// HealthDataType.SLEEP_LIGHT, | ||
// HealthDataType.SLEEP_DEEP, | ||
// HealthDataType.SLEEP_REM, | ||
// HealthDataType.SLEEP_SESSION, | ||
HealthDataType.WATER, | ||
HealthDataType.WORKOUT, | ||
HealthDataType.RESTING_HEART_RATE, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use
FlutterFragmentActivity
instead ofComponentActivity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the
ComponentActivity
in order to use the new api functionregisterForActivityResult
,FlutterFragmentActivity
is built upon the new Android apis which can be casted to aComponentActivity
. If you try to castFlutterActivity
to aComponentActivity
it will throw an error.