Referencing image in assets from HTML not working

故事扮演 提交于 2019-12-01 07:37:23

 webView.loadDataWithBaseURL("file:///android_asset/", sourse, "text/html", "UTF-8", null);
btschumy

OK, I finally figured this out. Apparently there is a bug somewhere in the Android code where it fails if the image path has a space in it. So:

<img src="file:///android_asset/SkyInfo/images/Deep Sky/M13-Misti.jpg">

will fail to load the image. If you change it to:

<img src="file:///android_asset/SkyInfo/images/DeepSky/M13-Misti.jpg">

it will work (assuming you've renamed the directory).

Note:

  • this is only a problem when reading from the assets.
  • appears to be an issue with Android 4.x. I have encountered this issue on 4.0.4 and 4.3 versions but spaces work just fine in 2.3.x version.

Come on Google, spaces in directory names have been common for 15 years. Get with the program.

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