I have an app, which should check on start, whether the location service is on, or off. I’ve tried to play around with AlerDialog
, and sending user to the settings via Intent
, but it doesn’t work as I’d like to.
I’ve changed approach, because I’d like to have location service checked after user will be back from settings, and wrote down following function:
@Composable
private fun TEST() {
val locationManager =
LocalContext.current.getSystemService(Context.LOCATION_SERVICE) as LocationManager
val locationPermissionLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
onResult = {
Log.i(TAG, "TEST: ${locationManager.isLocationEnabled}")
})
val context = LocalContext.current
LaunchedEffect(key1 = true) {
locationPermissionLauncher.launch(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))
}
}
Now, is it good approach? You can’t directly register activity for Intent service result, right? How I may approach it properly?