Question

I am trying to call a phone number programatically, but number is appending some unknown digits like "2255" or "011". My phone number format is : (###) ###-####. I just dont know how to solve this issue, or may be I dont know phone number formatting, can anybody help me please.

Was it helpful?

Solution

To start a call:

// 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);

OR (without starting the call)

/*
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 is a string like

String Number = "+493210210";

To filter a dirty number, use a filtering function, something like this:

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

and use it like:

Number = filter(Number);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top