我正在尝试覆盖默认的android错误对话框,当手机上没有安装simcard时,如果我们尝试拨打电话,它会显示出来。基本上,从我的应用程序,如果有人试图从电话进行呼出,如果没有安装simcard,那么我想使用sip服务进行呼叫。但问题是,有时一个默认的错误对话框出现,并显示一条消息,即没有安装SIM卡。下面是我的代码:
<receiver android:name=".OutgoingCallHandler">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>在android中:
@Override
public void onReceive(Context ctx, Intent intent) {
if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction())) {
String phoneNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
if (!isSimCardInstalled() && isSipServiceRunning()) {
ctx.sendBroadcast(new Intent(SipService.OUTGOING_CALL).putExtra(Intent.EXTRA_PHONE_NUMBER, checkCallingCode(phoneNumber)));
}
}要检查simcard:
public boolean isSimCardInstalled() {
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
return tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT ? true : false;
}它有时工作正常,有时电话显示内部电话错误消息。如何禁用此默认错误消息对话框?
发布于 2016-08-05 20:25:56
您需要防止广播Intent被下游应用程序处理(如标准的安卓拨号程序)。为此,请清除onReceive()中的结果数据,如下所示:
if (!isSimCardInstalled() && isSipServiceRunning()) {
ctx.sendBroadcast(new Intent(SipService.OUTGOING_CALL).putExtra(Intent.EXTRA_PHONE_NUMBER, checkCallingCode(phoneNumber)));
setResultData(null);
}https://stackoverflow.com/questions/38786217
复制相似问题