android / codelab-while-in-use-location

Codelab:
https://github.com/googlecodelabs/while-in-use-location
Apache License 2.0
81 stars 51 forks source link

Does not work in Android 11 or 12 #26

Open albintornqvist opened 2 years ago

albintornqvist commented 2 years ago

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.

fi8er1 commented 2 years ago

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