Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert android.net.Uri to java.net.URL? [duplicate]

Tags:

java

android

Is there a way to convert from Uri to URL? I need this for a library I'm using, it only accepts an URL but I need to use an image on my device.

like image 892
CaptainForge Avatar asked Jun 21 '16 13:06

CaptainForge


2 Answers

If the scheme of the Uri is http or https, new URL(uri.toString()) should work.

If the scheme of the Uri is file, that may still also work, though I get nervous.

If the scheme of the Uri is ftp or jar, that may still also work, though we will wonder why you have a Uri with those schemes.

If the scheme of the Uri is anything else — such as content — this will not work, and you need to find a better library.

like image 140
CommonsWare Avatar answered Oct 22 '22 05:10

CommonsWare


Try this

android.net.URI auri = new android.net.URI("your url goes here"); java.net.URI juri = new java.net.URI(auri.toString()); 

For more refer:

Android Uri

Java URI

like image 45
Pramod Waghmare Avatar answered Oct 22 '22 04:10

Pramod Waghmare