Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird characters in html webview

Im working on an android project where I open a webpage. I have a listener if the user has no internet connection. Instead of displaying the standard "page could not be found" im giving the webview a local html file stored in my assets folder. By this line of code:

web.loadUrl("file:///android_asset/html/404error.html");

In the HTML-file i think the encoding? is "utf-8", and it says something with javascript, if thats relevant.

Everything works fine except when displaying "ÅÄÖ", all those characters gets replaced by a "?"

Does someone know the solution?

Thanks!

like image 892
Sebastian Avatar asked Nov 13 '22 19:11

Sebastian


1 Answers

The browser/Webview needs to be told what encoding the document is in, otherwise it will guess some encoding or use the default one, which may be wrong. Usually you communicate the encoding using an HTTP header. If you're opening the file from local storage, obviously there's no HTTP involved. So you need to specify the encoding in the document header itself using

<meta http-equiv="Content-Type" content="text/html; charset=ENCODING HERE">

or, for HTML 5 documents:

<meta charset="ENCODING HERE">

Make sure the declaration matches how the document is actually encoded.

like image 61
deceze Avatar answered Nov 15 '22 11:11

deceze