Strange characters in html webview

I am working on an Android project where I open a webpage. I have a listener if the user does not have an Internet connection. Instead of displaying the standard โ€œpage could not be foundโ€, I give webview a local html file stored in my resource folder. On this line of code:

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

In the HTML file, I think the encoding? it's "utf-8" and it says something with javascript, if that matters.

Everything works fine, except for the display of "ร…ร„ร–", all these characters are replaced by the character "?"

Does anyone know a solution?

Thanks!

+4
source share
2 answers

I recently encountered the same problem as now. I solved this by changing the special characters from the HTML file to the corresponding HTML codes. You can get all the relevant HTML codes for special characters on google, but this one can help you.

0
source

The browser / webview should indicate what encoding the document is in, otherwise it will guess some encoding or use the default one, which may be incorrect. Usually you pass an encoding using an HTTP header. If you open the file from local storage, it is obvious that HTTP is not involved. Therefore, 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 ad matches the way the document is actually encoded.

0
source

Source: https://habr.com/ru/post/1442047/


All Articles