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

房东的猫 提交于 2019-12-21 21:42:06

问题


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.



来源:https://stackoverflow.com/questions/16570488/how-to-use-uri-parse-with-at-the-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!