I’d like to make a function, where user will be asked whether he would like to share his location, or just enter the city in TextField.
I’m struggling with implementing proper logic for this task. I’ve made an AlertDialog
, which will move user to the app settings whenever he’ll tap on confirm button, and after he will be back, I’d like to check, if the Location service
was actually turned on, since you can be moved to the settings, but don’t enable it. How I can achieve it?
@Composable
private fun DisplayRationale() {
val context = LocalContext.current
var shouldAskForCity by remember { mutableStateOf(false) }
var hasBeenInSettings by remember { mutableStateOf(false) }
if (!hasBeenInSettings && !shouldAskForCity) {
AlertDialog(
title = {
Text(text = "Application need data about your location")
},
text = {
Text(text = "In order to get proper forecast you can either turn on location service, or simply enter the city that you want see forecast for")
},
onDismissRequest = {
hasBeenInSettings = true
},
confirmButton = {
Button(onClick = {
hasBeenInSettings = true
context.startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))
}) {
Text(text = "Turn on location")
}
},
dismissButton = {
Button(onClick = { shouldAskForCity = true }) {
Text(text = "Enter city instead")
}
}
)
}
}
user24165946 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.