11

I want to call Emergency number using Android SDK.

I am using following code to call the number (911). This code works fine for all the numbers except 911 (Emergency Number). When I use 911, then it shows the dialer screen that I don't want. Is there any procedure to call 911 without open the dialer or can we stop the user to edit the number in Dialer screen?

Uri callUri = Uri.parse("tel://911");
Intent callIntent = new Intent(Intent.ACTION_DIAL,callUri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivity(callIntent);
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Amit Thaper
  • 2,117
  • 4
  • 26
  • 49

4 Answers4

7

The code provided should already work for this, but you need the CALL_PHONE and CALL_PRIVILEGED permission to dial emergency numbers without showing the dial-pad.

Android Reference - Manifest Permission CALL_PRIVILEGED

Once that is added to the manifest, you should be able to use the same code using the ACTION_CALL instead to direct dial:

Uri callUri = Uri.parse("tel://911");
Intent callIntent = new Intent(Intent.ACTION_CALL,callUri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivity(callIntent);
SandWyrm
  • 713
  • 9
  • 7
7

Action_Dial will open the dialpad, Action_Call will call directly..

However, a quote from ACTION_CALL:

Note: this Intent cannot be used to call emergency numbers. Applications can dial emergency numbers using ACTION_DIAL, however.

Maaalte
  • 6,011
  • 3
  • 29
  • 27
0

Say Intent.ACTION_CALL insted of Intent.ACTION_DIAL this will call number without showing it on dial pad.

Harshad
  • 7,904
  • 3
  • 24
  • 42
  • I tried it this will open the dialpad. This code will works only for other numbers not for 911. Are you sure that 911 call not show the dialpad please check at your end. I already use this code. if you done successfully then please post the Code – Amit Thaper Mar 14 '11 at 12:44
0
private fun startCall() {
    val callIntent = Intent(Intent.ACTION_CALL)
    callIntent.data = Uri.parse("tel:$phoneEmergency")
    startActivity(callIntent)
}

override fun onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<out String>,
    grantResults: IntArray
) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    if(requestCode == REQUEST_PHONE_CALL) startCall()
}

en el oncreate uso los bindings

binding.btnEmergency.setOnClickListener {

        if(ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CALL_PHONE), REQUEST_PHONE_CALL)
        }else{
            startCall()
        }
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 01 '23 at 09:59