Android loading local image with space in path and

2020-04-16 18:44发布

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.

2条回答
【Aperson】
2楼-- · 2020-04-16 18:50

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);
查看更多
地球回转人心会变
3楼-- · 2020-04-16 19:06

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

path = path.replace(" ","\u0020");
查看更多
登录 后发表回答