Is it possible to load an image from a remote server using ImageView.setImageURI(Uri uri)?
To load an image from a directory, it should be converted to a Drawable
first. Here is a piece of code which can help:
File file = new File ("/sdcard/1.jpg");
ImageView imageView = (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:
File file = new File ("/sdcard/1.jpg");
ImageView imageView = (ImageView) findViewById(R.id.icon);
imageView.setImageURI(Uri.fromFile(file));
Thanks to Martin Wibbels for this post.
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