To enable "Allow all the time" location permissions in an Android app, how to launch the location settings for the app in the Android settings?
I have seen how to launch the Android settings page for location (all apps), and how to launch the settings for a specific app, but not how to deep link to the location settings for a specific app.
This is what I currently have:
fun openAppLocationSettings(context: Context) {
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
val packageName = context.packageName
val uri = Uri.fromParts("package", packageName, null)
intent.data = uri
context.startActivity(intent)
}
but it only shows the root page of the app Settings.
The solution here is not to try to use an intent to launch the location settings in Android. The way Android works on Android API >= 30, is that you first need to request location permissions for coarse and fine location. After the user has allowed the permission, then make another location permission request, for background location. So:
Step 1:
val permissionsToRequest: Array<String> = arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
)
launcher.launch(permissionsToRequest)
Step 2 (assuming user allows coarse/fine location permission in step 1):
val permissionsToRequest: String =
Manifest.permission.ACCESS_BACKGROUND_LOCATION
launcher.launch(permissionsToRequest)
However, instead of a dialog coming up for the "Allow all the time" location permission, Android navigates user to the location settings for the Android app.
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