Referencing image in assets from HTML not working

后端 未结 2 1190
一生所求
一生所求 2021-01-14 01:17

I\'m trying to display an image in a WebView in an Android app. The image exists in the assets folder of my Android project. The HTML is programmatically built and has this

相关标签:
2条回答
  • 2021-01-14 01:57

    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.

    0 讨论(0)
  • 2021-01-14 02:06

    enter image description here

     webView.loadDataWithBaseURL("file:///android_asset/", sourse, "text/html", "UTF-8", null);
    
    0 讨论(0)
提交回复
热议问题