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