How can I call emergency number programmatically

Viewed 11095

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'?

13 Answers

I am also facing similar kind of issue in Android OS 10(Q),

W/Telecom: NewOutgoingCallIntentBroadcaster: Cannot call potential emergency number 911 with CALL Intent Intent { act=android.intent.action.CALL dat=tel:xxx flg=0x10000000 pkg=com.android.server.telecom cmp=com.android.server.telecom/.components.UserCallActivity (has extras) } unless caller is system or default dialer.: TSI.hCI->CIP.sNOCI@AO8

In that case below is my findings and fix. I hope this will help some one.

    Intent intent;
    if (PhoneUtil.isEmergencyNumber(number)) {
        intent = new Intent("com.android.phone.EmergencyDialer.DIAL");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                Intent.FLAG_ACTIVITY_NO_USER_ACTION);
        intent.setData(Uri.parse("tel:Your Emergency number "));

    } else {
        intent = new Intent(Intent.ACTION_CALL);
        intent.setPackage("com.android.server.telecom");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse("tel:Your number"));

    }
    startActivity(intent);
Related