My Android app targets SDK 28 and connects to Google Fit to upload data and read some other data. The app uses the HistoryAPI to read com.google.step_count.delta data.
This documentation claims that "com.google.android.gms.permission.ACTIVITY_RECOGNITION permission is converted into a pre-granted runtime permission" if the app targets SDK 28 but runs on SDK 29: https://developers.google.com/fit/android/authorization#android_permissions
I have added to the app's manifest like the documentation says to do.
When this Android app is on a device running Android 10 (SDK 29) and the user connects to Google Fit for the first time, I get a log saying:
There was a problem subscribing.com.google.android.gms.common.api.ApiException: 10: SecurityException: com.google.step_count.delta requires android.permission.ACTIVITY_RECOGNITION
Yet the documentation claims that this will be converted into a pre-granted runtime permission.
The team is not ready to migrate the app's target SDK to 29 just yet, so how can we continue to get com.google.step_count.delta data without this error?
I am assuming that this log means it didn't actually connect as there was no log statement that said:
Successfully subscribed to com.google.step_count.delta
Looks like the documentation was updated: https://developer.android.com/about/versions/10/privacy/changes#physical-activity-recognition
I was able to solve this by only using the API 28 permission in the manifest (com.google.android.gms.permission.ACTIVITY_RECOGNITION).
If the app was installed on a device running Android 10 (API 29), the system appears to correctly auto grant the permission android.permission.ACTIVITY_RECOGNITION.
Because the user can change this in settings (Settings > Apps & Notifications > Permission Manager > Physical Activity > specified app > deny), I was able to check the android.permission.ACTIVITY_RECOGNITION permission if the app was installed on a device running Android 10 (API 29).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With