From my side, I found that you can try to replace hash symbol with %23. So, you can try something like that:
%23
uri.toString().replace("#", "%23")
Also, it might be useful to use Uri.decode() before the replacement.
Uri.decode()