4

I have an application that calls a number stored by the user. Everything works okay unless the number contains commas or hash signs, in which case the Uri gets truncated after the digits. I have read that you need to encode the hash sign but even doing that, or without a hash sign, the commas never get passed through. However, they do get passed through if you just pick the number from your contacts. I must be doing something wrong. For example:

String number = "1234,,,,4#1";
Uri uri = Uri.parse(String.format("tel:%s", number));
try {
  startActivity(new Intent(callType, uri));
} catch (ActivityNotFoundException e) { ...

Only the number '1234' would end up in the dialer.

Rob Kent
  • 5,183
  • 4
  • 33
  • 54
  • 1
    Note that this is targetting Android 1.6 and it fails on the emulator, an HTC Magic, and a Motorola Droid running 2.01. – Rob Kent Mar 30 '10 at 06:44
  • See also https://stackoverflow.com/questions/5750773/sending-pause-to-dialer/9089375. – CoolMind Sep 27 '19 at 08:43

2 Answers2

1

Hashes and commas are reserved characters in URLs. Hence, convert both of those (comma is %2C, hash is %23) and see if that helps.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Sorry, I should have said that I already tried: String numberEncoded = URLEncoder.encode(number) which also failed. Which is odd because the documentation says: "Builds and parses URI references which conform to RFC 2396." But I get the same problem with encoded commas disappearing. – Rob Kent Mar 30 '10 at 06:22
  • And I also tried: Uri uri = Uri.fromParts("tel", number, null), which automatically encodes it, but with the same outcome. – Rob Kent Mar 30 '10 at 07:12
  • It's possible. I guess I will need to experiment with it and try and find a workaround. – Rob Kent Mar 30 '10 at 16:14
  • 1
    Has anyone found a solution to this problem? since in my country it is necessary to enter the telephone number "," and the extension, but when making the attempt, the native call application deletes all the content of the "," at the end. – Gerrard Jun 13 '19 at 20:31
  • Bad, misleading answer. – CoolMind Sep 27 '19 at 08:26
0

Works for me with ',' , '*' & '#':

Intent intentCallForward = new Intent(Intent.ACTION_CALL);                             
Uri uri = Uri.fromParts("tel", phoneNumber, "#"); 
intentCallForward.setData(uri);                                
startActivity(intentCallForward); 
Arnold
  • 323
  • 2
  • 15
  • 1
    The problem is that I am reading a phone number from a contacts list and the user may have entered any sequence as a string, eg '12345,,,#1' I read this and pass it via the URL intent. Maybe it is the URI.parse that is the problem. I'm no longer working on this so cannot test it. – Rob Kent Mar 12 '13 at 10:09
  • 1
    I also notice a related question has appeared after mine: http://stackoverflow.com/questions/3615886/sending-pause-and-dtmf-input-in-android?rq=1 – Rob Kent Mar 12 '13 at 10:10