My favorites | Sign in
Project Home Issues
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 3552: WebView.loadData() doesn't show Japanese characters
10 people starred this issue and may be notified of changes. Back to list
Status:  Declined
Closed:  Aug 2009

Sign in to add a comment
Reported by, Aug 13, 2009
Android version: 1.5_r3
OS: MS Windows XP SP3
The following code doesn't display any Japanese characters.

WebView wv = new WebView(this);
wv.loadData("<html><body>漢字テスト</body></html>", "text/html", "utf-8");

While the following code displays Japanese characters properly.

TextView tv = new TextView(this);
Aug 14, 2009
(No comment was entered for this change.)
Labels: Component-Browser
Aug 17, 2009
I think you need to escape the japanese text in UTF-8 for loadData().

  wv.loadData("<html><body>漢字テスト</body></html>", "text/html", "utf-8");

Aug 18, 2009
agreed; characters as shown is not encoded as utf-8
Status: Declined
Aug 18, 2009
Whatever code you see in the post is, the original code is in UTF-8.
Because, I tested it after I saved the source file in UTF-8.

Originally, I tried the following code but it didn't show the Japanese
characters. In this case, res/raw/help_jp.html is written in UTF-8.
html.loadUrl(sever_url + "/help_jp.html") shows the page correctly.

public class MyHtmlpage extends Activity {
    static final int MAX_HTML_SIZE = 4096;
    static final String ENCODING = "utf-8";
    public void onCreate(Bundle savedInstanceState) {
        WebView html = new WebView(this);
        InputStream is = getResources().openRawResource(R.raw.help_jp);
        byte[] buff = new byte[MAX_HTML_SIZE];
        int len;
        String rawText;
        try {
            len =, 0, MAX_HTML_SIZE);
            rawText = EncodingUtils.getString(buff, 0, len, ENCODING);
        } catch (Exception e) {
            rawText = "";
        html.loadData(rawText, "text/html", "utf-8");


Aug 19, 2009
Thanks for the additional diagnosis. Please note that the implementation for loadData is this:
    public void loadData(String data, String mimeType, String encoding) {
        loadUrl("data:" + mimeType + ";" + encoding + "," + data);
This means that 'data' needs to be URL encoded, since it is being passed to the browser in the same way you 
would type a web address. You may have more luck using this interface:
    public void loadData(String data, String mimeType, String encoding) {
        loadUrl("data:" + mimeType + ";" + encoding + "," + data);

Aug 20, 2009
Thanks for the suggestion. But it still has a problem. Blanks in the
URLencoded string appeared in the screen as "+" instead of a space.
Now the following code shows "漢字+テスト" instead of "漢字 テスト"
that I want to see on the screen. Any idea?

html.loadData(URLEncoder.encode("<html><body>漢字 テスト</body></html>", "utf-8"),
"text/html", "utf-8");

Aug 20, 2009
OK, I found a simple work around. The following code shows the text just fine.
Thanks for everyone.

webview.loadData(URLEncoder.encode("<html><body>漢字 テスト</body></html>",
"utf-8").replaceAll("\\+"," "), "text/html", "utf-8");

Mar 19, 2010
korean has same problem. so i try to add meta tag to html string

<meta http-equiv="Content-Type" content="text/html; charset=utf-16le">

in this case, solution is

wv.loadData("<html><meta http-equiv=\"Content-Type\" content=\"text/html; 
charset=utf-16le\"><body>漢字テスト</body></html>", "text/html", "utf-8");

i think android may ignore encording params in loadData()

Aug 23, 2010
(No comment was entered for this change.)
Dec 28, 2010
Slightly ridiculous that the <meta> tag is required to set the encoding appropriately, especially when loadData has an encoding param.  If it's not specified in the html, the WebView should default to the param value.
May 2, 2011
Thanks to all! Meta tagging the html solved my issue with non ASCII chars as well.
Apr 26, 2012
It seems that solution wiil fail in android 4.0!!
Jul 12, 2012
Reading the docs at, java.lang.String, java.lang.String), loadData() accepts only base64 or ASCII encodings, but loadDataWithBaseURL() can accept other encodings.

So, the following is a bit hacky but works for me:

wv.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
Apr 15, 2013
Alternative workaround for Android 4.0+

webView.loadData(htmlContent, "text/html; charset=UTF-8", "UTF-8")
Sign in to add a comment

Powered by Google Project Hosting