codelab-while-in-use-location icon indicating copy to clipboard operation
codelab-while-in-use-location copied to clipboard

Does not work in Android 11 or 12

Open albintornqvist opened this issue 4 years ago • 1 comments

Since some revision of Android 11, Foreground Services are no longer allowed to access location if started from the background (https://developer.android.com/about/versions/11/privacy/foreground-services). Starting a Foreground Service from the onUnbind-callback of an activity binding, as in this code lab, is considered background. This example should probably be removed or updated since it is kind of confusing right now that the guide for the code lab claims to support Android 11 (https://codelabs.developers.google.com/codelabs/while-in-use-location?hl=ko#0).

The way we solved it was by starting the Foreground Service and generating the notification as soon as the user starts the location tracking feature in our app (while the app is still visible to the user). I hope this helps anyone in the same situation as I was in.

albintornqvist avatar Nov 03 '21 09:11 albintornqvist

Then I don't see any point of binding and unbinding???

fi8er1 avatar Aug 24 '22 12:08 fi8er1