如何使用中心的hashtag创建Android Uri

如何使用中心的hashtag创建Android Uri,android,uri,urlencode,hashtag,uribuilder,Android,Uri,Urlencode,Hashtag,Uribuilder,我有以下Uri要构造 https://www.example.com/sub/#/action?firstparam=123456&secondparam=abcdef 我使用Android构建Uri Uri uri = new Uri.Builder().scheme(HTTPS_SCHEME).authority("www.example.com").appendPath("sub").appendPath("#").appendPath("action")appendQueryP

我有以下Uri要构造

https://www.example.com/sub/#/action?firstparam=123456&secondparam=abcdef
我使用Android构建Uri

Uri uri = new Uri.Builder().scheme(HTTPS_SCHEME).authority("www.example.com").appendPath("sub").appendPath("#").appendPath("action")appendQueryParameter(
            "firstparam", first).appendQueryParameter("secondparam", second).build();
但是hashtag是经过编码的,将产生以下Uri

https://www.example.com/sub/%23/action?firstparam=123456&secondparam=abcdef

如何预防?我尝试使用
片段
,但它在Uri的末尾添加了hashtag。

Uri.Builder就是这样工作的。它对非安全URL字符进行编码,其十六进制值具有特殊含义。在您的情况下,
被编码为
%23

为了防止这种使用:

builder.appendEncodedPath("#")