Convert String to Uri


Question

How can I convert a String to a Uri in Java (Android)? i.e.:

String myUrl = "http://stackoverflow.com";

myUri = ???;

1
155
7/30/2013 12:41:07 PM

Accepted Answer

You can use the parse static method from Uri

Uri myUri = Uri.parse("http://stackoverflow.com")
352
8/15/2010 12:48:57 PM

I am just using the java.net package. Here you can do the following:

String myUrl = "http://stackoverflow.com";
URI myURI = new URI(myUrl);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon