UTF8 issue in Android webView.loadUrl

2019-05-21 09:40发布

问题:

My webpage is working in all brwosers including iOS devices.But I use same page in Android app webview the characters are blank.

Original characters: "à´•à´°àµà´£à´¯à´±àµà´± ; നിസàµà´¨àµ‡à´¹à´®à´¾à´¯ ; à´¸àµà´¨àµ‡à´¹à´®à´¿à´²àµà´²à´¾à´¤àµà´¤"

After I use - meta http-equiv="Content-Type" content="text/html; charset=utf-8" its showing correct words in local language [കരുണയറ്റ ; നിസ്നേഹമായ ; സ്നേഹമില്ലാത്ത] but the same webpage not shoing in android webView.loadUrl.

回答1:

Try using this istead of webView.loadUrl(...):

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

or try this:

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


回答2:

Hey i suggest all of you facing unicode problem to test your app on real device mine was not working on emulator but when i tested on real device my app loaded all the unicode fonts may be sound silly but it really worked for me.Here are my codes

WebSettings settings = webView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
webView.loadUrl("http://kpbhandari.info/");


标签: android utf-8