我正在开发一个Android应用程序,其中有一个紧急号码调用功能。我正在使用下面的呼叫代码:
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();
}
和PhoneListener
类如下:
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);
}
}
}
当我使用INTENT.ACTION_CALL
时,呼叫应该自动发生。但对于紧急号码拨号盘显示(ACTION_DIAL
)。我已使用非紧急号码验证了相同的代码。通话自动进行。因此,Android不支持直接拨打紧急号码。我们无法为Android中的紧急号码调用ACTION.CALL
。请帮助我提供您的意见。
答案 0 :(得分:1)
在您的活动中调用此
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "911"));
startActivity(intent);
将此权限添加到您的清单:
<uses-permission android:name="android.permission.CALL_PHONE" />
答案 1 :(得分:0)
试试这个
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);
}