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'?
Emergency numbers require the user to fire the action himself.
Dialing 911 (US) is a mistake who could generate fees.
I worked around a project who calls 911 when a user falls. Obviously, it was for elderlies and/or injured people. When he falls, the emergency number is called.
You now have two options to simulate the "human action" as a basic AI.
1) Perform a click on the call button once dialed
Look at Phone app Android Samples and set an alarm which perform a clic on the call button. The sample will give you the button id.
2) Ask for permission (and the user HAS to allow it) following the API 23 modal : https://developer.android.com/training/permissions/requesting.html
The manifest isn't enough in this case.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With