tags:

views:

369

answers:

1

Hi,

I know the absolute path of an image (say for eg, /sdcard/cats.jpg). Is there any way to the content uri for this file ?

Actually in my code I download an image and save it at a particular location. In order to set the image in an ImageView currently I open the file using the path, get the bytes and create a bitmap and then set the bitmap in the ImageView. This is a very slow process, instead if I could get the content uri then I could very easily use the method ImageView.setImageUri(uri)

Thanks

A: 

Try with:

ImageView.setImageUri(Uri.fromFile(new File("/sdcard/cats.jpg")));

Or with:

ImageView.setImageUri(Uri.parse(new File("/sdcard/cats.jpg").toString()));
Francesco
I had tried the above mentioned method but it doesnot wor. It shows a log stating "resolveUri failed on bad bitmap uri: file:///sdcard/Cats.jpg"
frieza
I remember there was a bug into the ImageView.resolveUri() implementation. Try the second way. I have just updated my answer.BTW, Are u sure that the file exist?
Francesco
yes the file exists. And thanks, the second option worked :)
frieza