How can I call emergency number programmatically

stardust picture stardust · Dec 25, 2013 · Viewed 9.3k times · Source

I can call general phone number by following codes:

Intent intent = new Intent(Intent.ACTION_CALL);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("tel:" + phoneNumber));
startActivity(intent);  

in manifest file, I add permission like below:

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

as android's doc explain CALL_PRIVILEGED like this: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.Not for use by third-party applications.

And my app is located at packages/apps, so it is not a third-party application, right? So, why I still go straight to dial pad not the dialing user interface every time I call emergency number like '112'?

Answer

M D picture M D · Dec 25, 2013

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);