![](/img/trans.png)
[英]How to give Choice of Numbers to Call using Intent.ACTION_CALL?
[英]Android - How to activate calling Emergency numbers using Intent.ACTION_CALL?
我正在开发一个具有紧急电话呼叫功能的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
。 请协助我。
在您的活动中称呼它
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "911")); startActivity(intent);
将此权限添加到清单中: <uses-permission android:name="android.permission.CALL_PHONE" />
尝试这个
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.