Android Android - 3 months ago 5
Android Question

Not able to make a call when #31# is added

I am trying to implement calling facility from my app. When some condition is true, I am hiding my caller id by adding #31# before my number. Although if #31# is not added, call is made perfectly allright but when #31# is added, blank screen pops up, as if the Phone app is loading, and my application screen comes back. My code snippet is this

String ph = "123456789";
String phNumber;
if (hideCallerId) {
phNumber = "#31#" + ph;
}
else {
phNumber = ph;
}

Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+phNumber));
startActivity(intent);


Case 1: when phNumber is 123456789, then call is made without problem.

Case 2: when phNumber is #31#123456789, then blank screen pops up and user comes back to my application screen.

Although when I am dialing from my device using #31#123456789, call is successfully made.
What I am missing out. Can anybody help me out.

Links didn't helped me Link1.
Thanks in advance.

Answer

You simply have to encode the phone number.

String phonenumber = "03012345,1234,#31#,98765"; // , = pauses
encodedPhonenumber = URLEncoder.encode(phonenumber, "UTF-8");
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + encodedPhonenumber)));

You may want to have a look at this one. Not able to make a call when #31# is added