【问题标题】:Android loading local image with space in path and with universal image loaderAndroid使用路径中的空格和通用图像加载器加载本地图像
【发布时间】:2015-07-01 03:57:15
【问题描述】:

我正在开发 android 应用程序,我想在通用图像加载器的帮助下显示本地图像。但是当我尝试显示在其本地图像路径中有空间的图像时,它无法显示图像。我尝试了以下方式:

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

我收到以下错误:

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)

如果尝试加载其本地路径中没有空格的图像,则它可以正常工作,但路径中有空格的图像会导致问题。需要一些帮助。谢谢。

【问题讨论】:

  • UIL 是否获取字符串路径?也许您可以在通过 %20 之前对其进行转义?

标签: android imageview universal-image-loader


【解决方案1】:

实际上是通用图像加载器的问题。 https://github.com/nostra13/Android-Universal-Image-Loader/issues/371

因此,您只需解码图像路径即可删除空间。

根据上面链接中的讨论,我得到了解决方案:

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

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

【讨论】:

    【解决方案2】:

    你能不能尝试用“\u0020”替换空格;

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      • 2017-04-07
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 2016-08-12
      • 2012-07-11
      相关资源
      最近更新 更多