Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android URL to Uri

Tags:

android

I have to change URL to URI, please guide me how can I change it.

I have tried a lot, but not getting the solution. Any help is appreciated. I can also attach code snippet if required.

like image 561
Programmer Avatar asked Mar 12 '12 07:03

Programmer


People also ask

What is the URI in Android?

A URI is a uniform resource identifier while a URL is a uniform resource locator.

How check URI is valid Android?

Use URLUtil to validate the URL as below. It will return True if URL is valid and false if URL is invalid.


2 Answers

We can parse any URL using Uri.parse(String) method.

Code Snippet :

Uri uri =  Uri.parse( "http://www.stackoverflow.com" ); 
like image 141
Samir Mangroliya Avatar answered Oct 25 '22 10:10

Samir Mangroliya


final String myUrlStr = "xyz"; URL url; Uri uri; try {     url = new URL(myUrlStr);     uri = Uri.parse( url.toURI().toString() ); } catch (MalformedURLException e1) {     e1.printStackTrace(); } catch (URISyntaxException e) {     e.printStackTrace(); } 
like image 28
Sparky Avatar answered Oct 25 '22 11:10

Sparky