WebView: webpage not available but I load it from an html string

前端 未结 3 609
一个人的身影
一个人的身影 2021-01-15 02:06

My html string is like this:


3条回答
  •  伪装坚强ぢ
    2021-01-15 02:25

    I just encountered this issue and there quite a few related bug reports to do with it. I had an % is my inline CSS which resulted in the page not being rendered. I thought all was ok when I saw in the docs for WebView.loadData(...)

    The encoding parameter specifies whether the data is base64 or URL encoded. If the data is base64 encoded, the value of the encoding parameter must be 'base64'. For all other values of the parameter, including null, it is assumed that the data uses ASCII encoding for octets inside the range of safe URL characters and use the standard %xx hex encoding of URLs for octets outside that range. For example, '#', '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.

    but alas using base64 as instructed makes no difference. On my 4.3 device everything was fine but on 2.3 nothing would render. Looking at all the bug reports everyone suggested different stuff but the only thing that worked for me was using

    webView.loadDataWithBaseURL(null, data.content, "text/html", "UTF-8", null);

    be careful not to use text/html; instead of text/html as it will silently fail!

提交回复
热议问题