I have both ACCESS_FINE_LOCATION
and ACCESS_COARSE_LOCATION
in my manifest but assume I need to get the permission granted in realtime. On https://developer.android.com/training/location/permissions there is a sample
val locationPermissionRequest = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
) { permissions ->
when {
permissions.getOrDefault(Manifest.permission.ACCESS_FINE_LOCATION, false) -> {
// Precise location access granted.
}
permissions.getOrDefault(Manifest.permission.ACCESS_COARSE_LOCATION, false) -> {
// Only approximate location access granted.
} else -> {
// No location access granted.
}
}
}
but it has compilation "Unresolved reference: registerForActivityResult"
So I thought I could use ActivityCompat.requestPermissions()
as in https://stackoverflow.com/a/40955157/131391 but the first parameter for this method is an Activity
, while I have only a widget and no activity.
I'm not sure what to try next, to get location permission for my widget.