tags:

views:

422

answers:

1

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.

A: 

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
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
And I also tried: Uri uri = Uri.fromParts("tel", number, null), which automatically encodes it, but with the same outcome.
Rob Kent
Well, Dialtacts (the dialer/contacts app) may not be using `tel:` `Uri` number to do its work, since it is part of the operating system. It is possible this is just a limitation of `tel:` on Android.
CommonsWare
It's possible. I guess I will need to experiment with it and try and find a workaround.
Rob Kent