androidcharacter-encodingwebviewdownloadutf-32

downloaded non-english html file unreadable in webview


save (malayalam) string content code

    String A = "<html><head><style>"
            + "@font-face { font-family: Manorama;src: url(file:///android_asset/Manorama.ttf); }"
            + "h1 { color: #222;font-size: 26px;margin-top: 32px; }"
            + "</style></head><body><h1>"
            + "<font face=\"Manorama\">ØíxàW ¥çÄÞùßxßÏßW 190 æd¿ÏßÈß</font><!--3546062932-->"
            + "</p><body></html>";

    FileOutputStream OStream = null;
    try {
        OStream = openFileOutput("0.html", Context.MODE_PRIVATE);
        OStream.write(A.getBytes("UTF-32"));
        OStream.close();
    } catch (Exception e) {
    }

it is working perfectly

But when I do the same operation after downloading from server it doesn't work (characters are non readable in webview),

Find the code below,

        HttpClient client = new DefaultHttpClient();
        HttpResponse response = null;
        InputStream in = null;
        try {
            response = client.execute(new HttpGet(
                    "http://tinymail.in/mail_pipe/thozhilveedhi/pull"));
            in = response.getEntity().getContent();
        } catch (Exception e) {
        }
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(in));
        StringBuilder string = new StringBuilder();
        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                string.append(line);
            }
            in.close();
        } catch (Exception e) {
        }

        String[] A = (string.toString()).split("__");

        for (int i = 0; i < A.length; i++) {
            if (A[i] != "") {

                try {
                    FileOutputStream OStream = openFileOutput(i + ".html",
                            Context.MODE_PRIVATE);
                    OStream.write(A[i].getBytes("UTF-32"));
                    OStream.close();
                } catch (Exception e) {
                }

            }
        }

I think problem is at data transfer from server to android, what i can do ??
Does base 64 transfer encoding solve this problem ??
please help


Solution

  •         HttpClient client = new DefaultHttpClient();
            HttpResponse response = null;
    
            try {
                response = client.execute(new HttpGet(
                        "http://tinymail.in/mail_pipe/thozhilveedhi/pull"));
            } catch (Exception e) {
            }
    
            HttpEntity entity = response.getEntity();
            if (entity != null) {
    
                String data = EntityUtils.toString(entity);
                String[] A = null;
    

    ..
    to read file & the code below to save

                        try {
                            FileOutputStream OStream = openFileOutput(i
                                    + ".html", Context.MODE_PRIVATE);
                            OStream.write(A[i].getBytes("UTF-16"));
                            OStream.close();
                        } catch (Exception e) {
                        }
    
                    }
                }
    
            }