如果手机中未安装SIM卡,如何禁用/覆盖错误对话框

时间:2016-08-05 09:46:39

标签: android android-intent android-broadcastreceiver

我正在尝试覆盖默认的Android错误对话框,该对话框显示何时未在手机上安装SIM卡,以及我们是否尝试拨打电话。 基本上从我的应用程序,如果有人尝试从电话拨打电话,如果没有安装SIM卡,那么我想使用SIP服务拨打电话。但问题是有时出现默认错误对话框并显示无SIM卡安装的消息。这是我的代码:

> python client.py
200
Welcome, I don't think you've visited here before.
Set-Cookie: AIOHTTP_SESSION="gAAAAABXpF_SYEhcMpT-1Q_g6V-SwDuWh-XZipIMre5GgYvJ513ao4BaVgN4kcQM4b91umGCgWuoCEe5RCpZ5ryA30rchUAaojH3B35OL9LjH-kLJ3Md0PhfaylWl3_ct5K2aSwdBdMU_mACaHeTV0FA7yiT0DrMI_n9ct3D-jRTYCsKc5xLI2I="; Domain=localhost; HttpOnly; Path=/
200
Welcome, I don't think you've visited here before.
Set-Cookie: AIOHTTP_SESSION="gAAAAABXpF_SiCl07HDerId98tjI6hTrWOcEmCRVELV3F_sif3XkzgjS_hfwlkMK4HpoWbRrNoxJZpERPKkxRJi9AOpUeleWTkfkjXUcNk13OX5GCOZDSLbSbTkqdoiiAYfAsQ3CNHZWGWd2xzlha_E54ig3Jq1sQsAXV6rgcrqxh0xMGYWfseM="; Domain=localhost; HttpOnly; Path=/

在android中:

  <receiver android:name=".OutgoingCallHandler">
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
    </receiver>

检查simcard:

  @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)));
        }
    }

有时它可以正常工作,有时手机会显示内部手机错误信息。我如何禁用此默认错误消息对话框?

1 个答案:

答案 0 :(得分:0)

您需要阻止下游应用(例如标准Android拨号程序)处理广播Intent。为此,请清除onReceive()中的结果数据,如下所示:

    if (!isSimCardInstalled() && isSipServiceRunning())  {
        ctx.sendBroadcast(new Intent(SipService.OUTGOING_CALL).putExtra(Intent.EXTRA_PHONE_NUMBER, checkCallingCode(phoneNumber)));
        setResultData(null);
    }