flutter-plugins icon indicating copy to clipboard operation
flutter-plugins copied to clipboard

[HEALTH 9.0.0] askPermissions does not work

Open softkot opened this issue 1 year ago • 5 comments

Device / Emulator and OS

  • Device: [Mi 9T Pro]
  • OS: [Android 11 RKQ1.200826.002 MIUI Global 12.5.1]

Describe the bug

Asking permissions for

[
    HealthDataType.HEART_RATE,
    HealthDataType.DISTANCE_WALKING_RUNNING,
    HealthDataType.STEPS,
    HealthDataType.DISTANCE_DELTA,
]

works fine, but once include HealthDataType.WORKOUT it stops working.

AndroidManifest.xml has following declarations:

    <uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
    <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.health.READ_HEART_RATE"/>
    <uses-permission android:name="android.permission.health.READ_STEPS"/>
    <uses-permission android:name="android.permission.health.READ_EXERCISE"/>
    <uses-permission android:name="android.permission.health.READ_DISTANCE"/>
    <uses-permission android:name="android.permission.health.READ_SPEED"/>

softkot avatar Feb 02 '24 16:02 softkot

Same issue here, we also want to use the Workout data type.

ciriousjoker avatar Feb 02 '24 21:02 ciriousjoker

I found that it is wrong assumption to assert that WORKOUT is always about distance and calories as well.

You should review the approaches here here and here.

I would recommend to leave it to developer and access TotalCaloriesBurnedRecord and DistanceRecord as any other data types, do not mix it along with ExerciseSessionRecord on a framework level.

softkot avatar Feb 04 '24 09:02 softkot

Ah yes, in our case we have functional strength training workouts. There is no distance involved all exercises are stationary. We might add calories later but for now we don't need them either.

ciriousjoker avatar Feb 04 '24 09:02 ciriousjoker

I am using HealthDataType.WORKOUT and it's working fine. My AndroidManifest has:

    <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.health.READ_STEPS" />
    <uses-permission android:name="android.permission.health.READ_EXERCISE" />
    <uses-permission android:name="android.permission.health.READ_SPEED" />
    <uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED" />
    <uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />
    <uses-permission android:name="android.permission.health.READ_HEART_RATE"/>
    <uses-permission android:name="android.permission.health.READ_DISTANCE" />

Further, you may want to make sure your MainActivity.kt and AndroidManifest.xml is as per the example app. This comment will help:

https://github.com/cph-cachet/flutter-plugins/issues/888#issuecomment-1931983263

hagen00 avatar Feb 15 '24 09:02 hagen00

The example app is just fine, but i am talking about real app that have approved by google the only required scopes and those are ACTIVITY_RECOGNITION without CALORIES_BURNED cause we do not need them. Your code does not work this case and you force to use excessive permissions, that's is wrong by design,

softkot avatar Feb 15 '24 09:02 softkot