11

I had Database in which data stored in hindi as \u092e\u0948\u0902 \u0924\ and setting that content to webview using below.

  webview1.loadData(hindi_content, "text/html", "UTF-8");

But it will display as

hindi content display as

I don't know why that's happening. Any one please suggest. how to fix that !

user1621629
  • 765
  • 7
  • 19

5 Answers5

9

This happens because of a bug with the encoding parameter of loadData in most Android versions. This parameter is ignored for some reason so the UTF-8 based hindi characters will not be rendered. To fix this you can use one of the following alternatives.

webview1.loadData(hindi_content, "text/html; charset=UTF-8", null);


webview1.loadDataWithBaseURL(null, hindi_content, "text/html", "utf-8", null);
Leon Lucardie
  • 9,541
  • 4
  • 50
  • 70
4

This is a duplicate of this answer:

You will also need to unescape those sequences and to do that refer to How to Unescape Unicode in Java

Rendering UTF-8 in a WebView using loadData has been broken in some form or fashion forever. Issue 1733

Use loadDataWithBaseURL instead of loadData.

// Pretend this is an html document with those three characters
String scandinavianCharacters = "øæå";

// Won't render correctly
webView.loadData(scandinavianCharacters, "text/html", "UTF-8");

// Will render correctly
webView.loadDataWithBaseURL(null, scandinavianCharacters, "text/html", "UTF-8", null);

Now the part that is truly annoying is that on the Samsung Galaxy S II (4.0.3) loadData() works just fine, but testing on the Galaxy Nexus (4.0.2) the multi-byte characters are garbled unless you use loadDataWithBaseURL(). WebView Documentation

Community
  • 1
  • 1
Cameron Lowell Palmer
  • 21,528
  • 7
  • 125
  • 126
1

you will need to use font in order to support hindi (Hindi language is not yet fully supported by android) create Singleton instance of Typeface and invoke createFromAsset(); and add it to WebSettings like this

WebSettings webSettings = webView.getSettings();
webSettings.setFixedFontFamily(InstaceOFTypeFace);
Shushant
  • 1,625
  • 1
  • 13
  • 23
1

Finally I have come up with the solution of Loading hindi content to the webview.

I had simply change my loading string and unfortunately it will work.

webview.loadData(Hindi_css, "text/html; charset=UTF-8", null);

Thank you all for your effort. :)

user1621629
  • 765
  • 7
  • 19
0

You can use this one also.

String uri= Uri.encode(html file/url);
  webView.loadUrl(uri);

may be this will help you.

Tapesh
  • 372
  • 1
  • 6
  • 17