Open stream from uri

You will have to create a new URL object and then open stream on the URL instance. An example is below.

try {

   URL url = uri.toURL(); //get URL from your uri object
   InputStream stream = url.openStream();

} catch (MalformedURLException e) {
   e.printStackTrace();
} catch (URISyntaxException e) {
   e.printStackTrace();
}catch (IOException e) {
   e.printStackTrace();
}

uri.toURL().openStream() or uri.toURL().openConnection().getInputStream()


You should use ContentResolver to obtain InputStream:

InputStream is = getContentResolver().openInputStream(uri);

Code is valid inside Activity object scope.


URLConnection connection = uri.toURL().openConnection()

Yes, you have to use the URL class in one way or the other.

Tags:

Java

Uri