I am trying to make an option in my app that calls 911, but when I click on the text in the lazycolumn that I should call it takes me to the phone system application and just there I can press to call 911. How can I get him to call that emergency number without taking me there?
fun makeACall(context: Context, phoneNumber: String) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) ==
PackageManager.PERMISSION_GRANTED
) {
val intent = Intent(Intent.ACTION_CALL)
intent.data = Uri.parse("tel: $phoneNumber")
startActivity(context, intent, bundleOf())
} else {
ActivityCompat.requestPermissions(
this, arrayOf(Manifest.permission.CALL_PHONE), 777
)
}
}
@Preview
@Composable
fun Columna() {
LazyColumn(
modifier = Modifier
.fillMaxSize()
.background(Color.Gray)
)
{
item {
PhoneNumber(title = "911 (Emergencias)", phoneNumber = "911")
}
}
}
@Composable
fun PhoneNumber(title: String, phoneNumber: String) {
val context = LocalContext.current
Text(
text = title,
fontSize = 32.sp,
color = Color.White,
modifier = Modifier
.fillMaxWidth()
.clickable { makeACall(context = context, phoneNumber = phoneNumber) },
textAlign = TextAlign.Center
)
}