Friday, November 26, 2010

ImageView.setImageURI does not work for file URIs

The following code fails:

File f = ...
ImageView imageView = ...
imgView.setImageURI(Uri.fromFile(f));

Workaround:

imgView.setImageDrawable(Drawable.createFromPath(f.getAbsolutePath()));

2 comments:

JiaHao Liu Liu said...

Thanks. It is very useful!

Lars said...

It actually works for file URIs for me (API version 15 I think). But maybe that's a new behavior.
Good to know about the workaround for older API levels.