我正在开发一个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不支持直接拨打紧急号码。我们不能在安卓系统中调用紧急号码( ACTION.CALL
)吗?请帮我拿你的资料。
发布于 2013-11-16 09:42:27
在你的活动中把这个叫做
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "911")); startActivity(intent);
将此权限添加到清单中:<uses-permission android:name="android.permission.CALL_PHONE" />
发布于 2014-03-17 09:47:39
尝尝这个
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);
}
https://stackoverflow.com/questions/20016593
复制相似问题