Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView shows source html with loadDataWithBaseURL, not rendered view

I'm developing an application witch uses WebView to render custom html. But when I call
loadDAtaWithBaseURL(URL, "<html><h1>TEST</h1></html>", "text/html; charset=utf-8;", "utf-8", null);
it shows html itself (not rendered one) on Genymotion emulator. On my HTC-one, it works fine with rendered html. Each result is showed as attached.

Shown result on Genymotion emulatorShown result on HTC one

Does anyone have a same problem or solution? Thanks.

like image 703
user2779344 Avatar asked May 24 '15 07:05

user2779344


1 Answers

Don't enter mimeType below KitKat.

fun getMimeType(): String? {
    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        "text/html; charset=utf-8"
    } else {
        null
    }
}
loadDAtaWithBaseURL(URL, "<html><h1>TEST</h1></html>", getMimeType(), "utf-8", null);

Java:

if(Build.VERSION.SDK_INT < 21)
    webView.loadDataWithBaseURL("about:blank","<html><h1>TEST</h1></html>","text/html", "UTF-8",null);
else
    webView.loadDataWithBaseURL("about:blank","<html><h1>TEST</h1></html>","text/html; charset=utf-8", "UTF-8",null);
like image 153
Salih Balkan Avatar answered Oct 06 '22 03:10

Salih Balkan