Is it even possible? I would like to be able to create a listener which will be notified about location permission changes (whether the app triggers them or not). As far as I can see, there are methods for getting the current permission status and methods for requesting permission but nothing which would simply allow the app to listen for changes.
For example, in iOS, we can set a delegate on a CLLocationManager
which will then be called via the locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus)
on any change in authorisation status. Does anyone know of any equivalent in Android (preferably compatible with API >= 17)?
Location permissions. If your app needs to access the user's location, you must request permission by adding the relevant Android location permissions to your app. Android offers two location permissions: ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION .
Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.
Checking for location manager: lm. getAllProviders(). contains(LocationManager. GPS_PROVIDER) (or NETWORK_PROVIDER ) would make sure that you do not throw the user to a settings page where there is no network option.
Is it even possible?
No, sorry.
As far as I can see, there are methods for getting the current permission status and methods for requesting permission but nothing which would simply allow the app to listen for changes.
If the user grants you permission, the only way that you find out is if you call checkSelfPermission()
again.
If the user revokes a previously-granted permission, as Michael suggests in a comment, your process is terminated, and you would find out about the permission change by calling checkSelfPermission()
the next time your app runs.
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