Reputation: 2698
Hello I use Universal Image Loader to load images from the device , now it works, but if the file path contains a "space character" the image does not get displayed and log records show that there is a FileNotFoundException
.
I tried to open the file in a thread using java io and it opens and I can read it.
the file name :
/mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20121014-WA0001.jp
when the Exception thrown
it replace the space with a %20
and this what makes the exception thrown.
My code:
ImageLoader.getInstance().displayImage(
Uri.fromFile(
new File(cursor.getString(cursor.getColumnIndex(
MediaStore.Images.Media.DATA)))).toString(),
holder.mImage);
works only when no spaces in the path ,
Any help
Upvotes: 4
Views: 6708
Reputation: 3385
The other answer unfortunately isn't too clear on what fileName
is so after some additional digging I managed to use local image with imageloader using:
Sample Code:
string imgPath = "/mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20121014-WA0001.jpg";
String decodedImgUri = Uri.fromFile(new File(imgPath)).toString();
ImageLoader.getInstance().displayImage(decodedImgUri, imageView);
Android loading local image with space in path and with universal image loader also helped to resolve this.
Upvotes: 12
Reputation: 1341
I had the same problem and I found this solution.
String uri = fileName.getUri().toString();
String decodedUri = Uri.decode(uri);
ImageLoader.getInstance().displayImage(decodedUri, imageView);
Upvotes: 5