4

what's the best way to convert an Uri (android) object to a URI (java.net) object and vice versa? I'm converting Uri to URI by using:

Uri androidUri;
URI netURI= new URI(androidUri.toString());

but I don't know if that's the best way to do it and I don't know how to reverse it.

Federico Taschin
  • 1,649
  • 3
  • 12
  • 21

1 Answers1

2

Both snippets worked for me.

Process-1

Uri newUri = Uri.parse(androidUri.toString());

Process-2

URI androidUri;
Uri newUri  = new Uri.Builder().scheme(androidUri.getScheme())
                    .encodedAuthority(androidUri.getRawAuthority())
                    .encodedPath(androidUri.getRawPath())
                    .query(androidUri.getRawQuery())
                    .fragment(androidUri.getRawFragment())
                    .build();
aslamconsole
  • 1,090
  • 10
  • 22