Web view Error using HTML content in Android

2019-08-31 05:28发布

问题:

Errors I am getting when passing Html(textstring) content value to webview.loaddata(textstring , "text/html", "utf-8");

Works fine in gingerbread,jellybean etc....but facing problem in Ice cream sandwich....Please help me to solve this

02-08 13:52:56.899: W/webcore(1694): java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.
02-08 13:52:56.899: W/webcore(1694):    at android.webkit.WebViewCore$EventHub.removeMessages(WebViewCore.java:1671)
02-08 13:52:56.899: W/webcore(1694):    at android.webkit.WebViewCore$EventHub.access$7800(WebViewCore.java:920)
02-08 13:52:56.899: W/webcore(1694):    at android.webkit.WebViewCore.removeMessages(WebViewCore.java:1783)
02-08 13:52:56.899: W/webcore(1694):    at android.webkit.WebView.sendOurVisibleRect(WebView.java:2858)
02-08 13:52:56.899: W/webcore(1694):    at android.webkit.ZoomManager.setZoomScale(ZoomManager.java:586)
02-08 13:52:56.899: W/webcore(1694):    at android.webkit.ZoomManager.access$1700(ZoomManager.java:49)
02-08 13:52:56.899: W/webcore(1694):    at android.webkit.ZoomManager$PostScale.run(ZoomManager.java:977)

回答1:

Try this I this that will help to you

String data = ...;  // the html data
String base64 = android.util.Base64.encodeToString(data.getBytes("UTF-8"),  
android.util.Base64.DEFAULT);
webView.loadData(base64, "text/html; charset=utf-8", "base64");

and you try this also

   webView.getSettings().setDefaultTextEncodingName("utf-8");      
   webView.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);

And also refer this link

UTF-8 encoding on WebView and ICS