当我要打电话时,电话号码附加一些未知数字

时间:2014-01-25 13:30:30

标签: android phone-call

我正在尝试以编程方式拨打电话号码,但号码附加了一些未知数字,如“2255”或“011”。我的电话号码格式为:(###)### - ####。我只是不知道如何解决这个问题,或者可能是我不知道电话号码格式,请有人帮助我。

1 个答案:

答案 0 :(得分:2)

开始通话:

// Requires the CALL_PHONE permission (it really starts a call).
final Intent tnt = new Intent(Intent.ACTION_CALL);
tnt.setData(Uri.parse("tel:" + Number));
tnt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(tnt);

或(不开始通话)

/*
Doesn't require the CALL_PHONE permission.
It doesn't start the call, but brings you to the dialer window.
*/
final Intent tnt = new Intent(Intent.ACTION_DIAL);
tnt.setData(Uri.parse("tel:" + Number));
tnt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(tnt);

Number是一个类似

的字符串
String Number = "+493210210";

要过滤号码,请使用过滤功能,如下所示:

private final String Filter(String Number)
{
    String result = Number;
    result = result.replace("#", "");
    result = result.replace("(", "");
    result = result.replace(")", "");
    result = result.replace("-", "");
    result = result.replace("*", "");
    result = result.replace(".", "");
    result = result.replace("/", "");
    result = result.replace("\", "");
    result = result.replace(" ", "");
    result = result.replace(" ", "");
    return result;
}

并使用它:

Number = filter(Number);