ACTION_CALL在Nexus/Android 4.3上充当ACTION_拨号,用于从08开始的号码
我有一个应用程序,它的布局中只有一个edittext和按钮ACTION_CALL在Nexus/Android 4.3上充当ACTION_拨号,用于从08开始的号码,android,android-intent,phone-call,Android,Android Intent,Phone Call,我有一个应用程序,它的布局中只有一个edittext和按钮 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" androi
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:inputType="phone" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editText1"
android:layout_below="@+id/editText1"
android:text="Dial" />
</RelativeLayout>
对于不以“08…”开头的号码,它会按预期调用该号码。对于以“08…”开头的号码,它会调出带有已填号码的拨号器。我怎样才能阻止这一切?这似乎不是手机上的设置,至少在我看来不是这样,但我在4.3模拟器上测试了它,它按预期工作。我没有其他的4.3手机可以测试。我的4.2.2 HTC One拨号与预期一致,我的所有旧测试设备也是如此
我可以直接拨打0800号码,或者在应用程序启动拨号程序后点击呼叫按钮,这样它们就不会被完全屏蔽,而且我在手机中没有sim卡的情况下也能得到同样的效果,所以不是这样
ETA:我可以通过在08号前加上“,”来解决这个问题,这会导致拨号前稍有停顿,但在其他情况下会起作用。不过,这并不能真正解释为什么会发生这种情况。我没有4.3手机可供测试。 但是,我查看了的源代码,其角色描述如下: OutgoingCallBroadcaster接收CALL和CALL\u PRIVILEGED intent,并广播ACTION\u NEW\u OUTGOING\u CALL intent,允许其他应用程序监视、重定向或阻止传出呼叫 它的processIntent(Intent i)方法包含一个片段(在第493行附近),将Intent的操作更改为action_拨号,前提是该号码被视为“潜在紧急” 总而言之,Android有一个用拨号板截取行动电话的策略。不过,我不太清楚为什么会发生这种情况
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editText1 = (EditText) findViewById(R.id.editText1);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String strNumber = editText1.getText().toString();
if (!strNumber.equals(""))
{
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + strNumber));
startActivity(intent);
}
}
});
}