-->

How to use Uri.parse() with # at the end

2020-07-24 05:31发布

问题:

I try to use GSM codes to transfer my calls with an android app. For example, if I call : **21*otherNumber# All my calls will be transfered on otherNumber.

My code:

Uri transfert = Uri.parse( "tel:**21*" + numero + "#");
Intent intent = new Intent( Intent.ACTION_CALL, transfert );
startActivity(intent);

However, Uri.parse() has for definition: " A URI reference includes a URI and a fragment, the component of the URI following a '#' "

So, it removes the # but I need it. The GSM code can't works without it.

Somebody would have an idea ?

回答1:

I don't think you can't dial phone number with extensions, it's a known issue (see this).

According to this thread, you may try to add %23 like Uri.parse( "tel:**21*" + numero + "%23");



回答2:

You need to send a URI encoded hash to parse it through the URI.

public static final String encodedHash = Uri.encode("#");

It will keep the URI encoded hash and send the USSD message over GSM as you have specified.