Android loading local image with space in path and with universal image loader

别等时光非礼了梦想. 提交于 2019-12-02 02:41:34

问题


I am developing android application in which I want to display local image with the help of universal image loader. But when I try to display image which has space in it's local image path then it not able to display image. I tried it in following manner:

Uri.fromFile(new File(newImagePath)).toString();

I am getting following error:

java.io.FileNotFoundException: /storage/emulated/0/WhatsApp/Media/WhatsApp%20Images/IMG-20150421-WA0002.jpg: open failed: ENOENT (No such file or directory)
        at libcore.io.IoBridge.open(IoBridge.java:456)

If tried to load image which has no space in its local path then it works fine but image with space in its path cause issue. Need some help. Thank you.


回答1:


Actually its problem with universal image loader. https://github.com/nostra13/Android-Universal-Image-Loader/issues/371

So you just have decode your image path to remove space.

As per discussion in above link I got the solution :

final String uri = Uri.fromFile(file).toString();
final String decoded = Uri.decode(uri);

ImageLoader.getInstance().displayImage(decoded, imageView);



回答2:


Can you try to replace space with "\u0020";

path = path.replace(" ","\u0020");


来源:https://stackoverflow.com/questions/29815417/android-loading-local-image-with-space-in-path-and-with-universal-image-loader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!