WebView not displaying UTF-8 Data

If you have a WebView and you want to display html code, you will probably use the WebView.loadData function as seen in the example here.

String htmlCode = "<html><body><b>hello man!</b> non bold text</body></html>";
mWebView.loadData(htmlCode, "text/html", "UTF-8");

Done by the book, nice try, though it does not always work.
When the html code contains UTF data, you have to base encode all the html data.
You can accomplish that by using the loadDataWithBaseURL function.
example:

String htmlCode = "<html><body><b>hello man!</b> non bold text</body></html>";
mWebView.loadDataWithBaseURL(null, htmlCode, "text/html", "UTF-8", null);

Ready :)

FacebookGoogle BookmarksTwitterFriendFeedGoogle GmailBlogger PostGoogle ReaderHotmailWordPressShare

Related posts:

  1. WebView: Change background and font color
  2. Transform HTML entities to normal text
  3. Android transparent webview
  4. How to play/embed YouTube videos in WebView
  5. Back in Android’s WebView

Tags: , , ,

Leave a Comment