Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView with garbled UTF-8 characters.

I'm using some webviews in my android app, but are unable to make them display in utf-8 encoding.

If use this one I won't see my scandinavian charcters:

mWebView.loadUrl("file:///android_asset/om.html") 

And if try this one, I won't get anything displayed at all

mWebView.loadDataWithBaseURL("file:///android_asset/om.html", null, "text/html", "utf-8",null); 

Regards

like image 683
elwis Avatar asked Feb 08 '11 12:02

elwis


1 Answers

You can try to edit the settings of your webview before you load the data:

WebSettings settings = mWebView.getSettings(); settings.setDefaultTextEncodingName("utf-8"); 

Also, as provided in the comment below, be sure to add "charset=utf-8" to the loadData call:

mWebView.loadData(getString(R.string.info_texto), "text/html; charset=utf-8", "utf-8"); 
like image 163
Eric Nordvik Avatar answered Oct 09 '22 23:10

Eric Nordvik