Skip to content Skip to sidebar Skip to footer

Does Imageview.setimageuri(uri Uri) Work With Remote Files?

Is it possible to load an image from a remote server using ImageView.setImageURI(Uri uri)?

Solution 1:

The short answer is no! It can't.

You could use ImageView.setImageURI(Uri uri) for instance if the uri contains a reference to a local file. Eg: file:///sdcard/images/thumb.png

Solution 2:

To load an image from a directory, it should be converted to a Drawable first. Here is a piece of code which can help:

Filefile=newFile ("/sdcard/1.jpg");

ImageViewimageView= (ImageView) findViewById(R.id.icon);

imageView.setImageDrawable(Drawable.createFromPath(file.getAbsolutePath()));

Be warned that there is another method for ImageView called setImageURI(URI uri). This method is used to load external files; it doesn't work with the type File. For example, this code won't work:

Filefile=newFile ("/sdcard/1.jpg");

ImageViewimageView= (ImageView) findViewById(R.id.icon);

imageView.setImageURI(Uri.fromFile(file));

Thanks to Martin Wibbels for this post.

Post a Comment for "Does Imageview.setimageuri(uri Uri) Work With Remote Files?"