1

I am trying to make a phone call in Android Studio with Kotlin; the objetive is to call the emergency telephone number "911" in Mexico. When I press the call button the app only show me the telephone number ("911" in the native app of the cellphone) instead of calling automatically. At the beginning I thought It was because of the "Intent", then I changed the number using "+" or "(52)44.." and It worked! I don´t know what could be the problem.

Permissions: <uses-permission android:name="android.permission.CALL_PHONE"/>

Code:

imageLlamada.setOnClickListener({

                makePhoneCall("911")


            })

    fun makePhoneCall(number: String) : Boolean {
    try {
        val intent = Intent(Intent.ACTION_CALL)
        intent.setData(Uri.parse("tel:$number"))
        startActivity(intent)
        return true
    } catch (e: Exception) {
        e.printStackTrace()
        return false
    }
}
Emmanuel
  • 21
  • 1
  • 5

1 Answers1

1

You need CALL_PRIVILEGED permission to call emergency numbers.

http://developer.android.com/reference/android/Manifest.permission.html#CALL_PRIVILEGED

Allows an application to call any phone number, including emergency numbers, without going through the Dialer user interface for the user to confirm the call being placed.

Kars
  • 845
  • 1
  • 14
  • 33
  • This is what i get when I try to use CALL_PRIVILEGED: Permissions with the protection level signature, privileged or signatureOrSystem are only granted to system apps. If an app is a regular non-system app, it will never be able to use these permissions. – Emmanuel Mar 20 '19 at 20:38
  • https://stackoverflow.com/questions/13801984/permission-is-only-granted-to-system-app – Kars Mar 20 '19 at 22:34
  • Do you know if I have to add the CALL_PRIVILEGED as a "uses-permission" label? Because I have done that and my call button does not do anything. Also, I checked the "Permission is only granted to system app" and I did that, but It is not working. – Emmanuel Mar 21 '19 at 17:03