loadData tries to use data as url in webview

android, webview

Solution

webContent.loadDataWithBaseURL(null, page, "text/html", "UTF-8")

works for me, while with loadData() I get sometimes your problem

Problem

``` page = "<!DOCTYPE HTML><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" + "</head><body>" + page + "</body></html>"; webContent.loadData(page, "text/html;charset=UTF-8", "UTF-8"); ``` On the call to loadData the webview gives "URL is invalid", in the onReceivedError callback the url is "data:text/html;charset=UTF-8;UTF-8,%3C!DOCTYPE%20HTML%3E .... /body%3E%3C/html%3E". This doesn't happen on all the data I load. Note: - in jelly bean everything works fine, this problem occurs while testing on 2.3 - I've tried loading data with loadDataWithBaseURL but the webview does't interpret the html, just shows the string content. Thank you!

Original source