I am using Webview and loadData method like this :
try {
htmlEncode = URLEncoder.encode(html, "UTF-8").replaceAll("\\+", " ");
} catch (UnsupportedEncodingException e) {
htmlEncode = html;
e.printStackTrace();
}
webView.loadData( htmlEncode,"text/html; charset=UTF-8", "UTF-8");
html is “html string”. Those of code is work fine in all android version except android 4.0.4. The webView don’t understand \n character. It can’t break to new line.
I and my partner searching for hours but can’t find any solution for this.
There are some reason we can’t use loadDataWithBaseURL() method.
Have you ever faced this problem ? or do you have any idea for us to find out what the wrong ?
I resoled my problem. I use webview by this way: Add webview to layout at runtime. So, when I use loadDataWithBaseURL() on Android 4.0.4. It can’t show html string so I used loadData() method instead. But when I used loadData() method some time the webview can’t show the content too, or have many problem with html string encode. But now I have solution.
I dont’ know why we have to delay a little time before calling loadDataWithBaseURL method.
But as my guess, maybe because the webview need time to init before load the html string.
Hope it help someone have this problem in future.