I am developing an Android application in which there is an Emergency numbers calling functionality. I am using the call code below:
private void call(String pnum) {
private TelephonyManager telephone;
private PhoneListener phList;
telephone = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
phList = new PhoneListener(this);
telephone.listen(phList, PhoneStateListener.LISTEN_CALL_STATE);
Intent call = new Intent(Intent.ACTION_CALL);
call.setData(Uri.parse("tel:" + pnum));
call.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(call);
finish();
}
and the PhoneListener
class is as below:
public class PhoneListener extends PhoneStateListener {
boolean called = false;
TelephonyManager mTelMgr;
InitiateScreen m;
public PhoneListener(InitiateScreen activity) {
mTelMgr = (TelephonyManager) activity
.getSystemService(Context.TELEPHONY_SERVICE);
m = activity;
}
@Override
public void onCallStateChanged(int state, String inNum) {
super.onCallStateChanged(state, inNum);
// Don't fire before the call was made
if (state == TelephonyManager.CALL_STATE_OFFHOOK)
called = true;
// Call has ended -- now bring the activity back to front
if (called && state == TelephonyManager.CALL_STATE_IDLE) {
called = false;
mTelMgr.listen(this, PhoneStateListener.LISTEN_NONE);
}
}
}
As i am using INTENT.ACTION_CALL
, the call should be automatically happened. But for Emergency numbers Dial Pad showing( ACTION_DIAL
). I have verified the same code with non-emergency numbers. Call is automatically going. So, Doesn't Android supports calling the Emergency numbers directly. Can't we invoke ACTION.CALL
for Emergency numbers in Android. Please help me with your inputs.
Call this in your activity
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "911")); startActivity(intent);
Add this permission to your manifest: <uses-permission android:name="android.permission.CALL_PHONE" />
try this
private void phoneCall()
{
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+txtPhn.getText().toString().trim()));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.