Android: raw resource file encoding

I am switching to translating one of my applications into Spanish and I have a problem with character encoding with a raw HTML file that I embed in a WebView. I have a Spanish translation of the file into the raw-es folder, and I read it with the following function:

private CharSequence getHtmlText(Activity activity) {
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.help), "utf-8"));
            String line;
            StringBuilder buffer = new StringBuilder();
            while ((line = in.readLine()) != null) buffer.append(line).append('\n');
            return buffer;
        } catch (IOException e) {
            return "";
        } finally {
            closeStream(in);
        }
    }

But everywhere in the file there is a Spanish symbol, there is a diamond with a question mark inside it when I launch the application, and look at the activity that displays the HTML. To load text into a WebView, I use the following:

mWebView.loadData(text, "text/html", "utf-8");

I originally created the file in Microsoft Word, so I'm sure that a character encoding problem is occurring, but I'm not sure how to fix it, and a Google search does not help. Any ideas?

+2
source share
2 answers

loadData. loadDataWithBaseURL. :

mWebView.loadDataWithBaseURL( null, text, "text/html", "utf-8", null );
+12

, , , . , Eclipse "ISO-8859-1". , .

0

All Articles