如果未在 phone 中安装 simcard,如何 disabled/override 出现错误对话框
How to disabled/override error dialog if simcard is not installed in phone
我正在尝试覆盖默认的 android 错误对话框,当 simcard 未安装在 phone 上并且我们尝试拨出电话时,该对话框会显示。
如果有人尝试从 phone 拨打电话,并且未安装 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)));
}
}
检查 sim 卡:
public boolean isSimCardInstalled() {
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
return tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT ? true : false;
}
有时工作正常,有时 phone 显示内部 phone 错误消息。我如何禁用此默认错误消息对话框?
您需要防止广播 Intent
被下游应用程序处理(例如标准 Android 拨号程序)。为此,清除 onReceive()
中的结果数据,如下所示:
if (!isSimCardInstalled() && isSipServiceRunning()) {
ctx.sendBroadcast(new Intent(SipService.OUTGOING_CALL).putExtra(Intent.EXTRA_PHONE_NUMBER, checkCallingCode(phoneNumber)));
setResultData(null);
}
我正在尝试覆盖默认的 android 错误对话框,当 simcard 未安装在 phone 上并且我们尝试拨出电话时,该对话框会显示。 如果有人尝试从 phone 拨打电话,并且未安装 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)));
}
}
检查 sim 卡:
public boolean isSimCardInstalled() {
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
return tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT ? true : false;
}
有时工作正常,有时 phone 显示内部 phone 错误消息。我如何禁用此默认错误消息对话框?
您需要防止广播 Intent
被下游应用程序处理(例如标准 Android 拨号程序)。为此,清除 onReceive()
中的结果数据,如下所示:
if (!isSimCardInstalled() && isSipServiceRunning()) {
ctx.sendBroadcast(new Intent(SipService.OUTGOING_CALL).putExtra(Intent.EXTRA_PHONE_NUMBER, checkCallingCode(phoneNumber)));
setResultData(null);
}