Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webview's loadData() is not working in android 10.0 (Q)

Here i am trying to load Html code as string in webview's loadData() .Nothing is happen over this mehtod but same method is working like charm in below sdk 29.

webview.loadData(html_code,"text/html",null);

Note : Here i am not performing any encoding or decoding operation on string.I am simply passing it as string to above method.

like image 435
Ashwin Nirmale Avatar asked Nov 27 '22 16:11

Ashwin Nirmale


2 Answers

Use this code, it will work.

String newhtml_code = Base64.encodeToString(html_code.getBytes(), Base64.NO_PADDING);
        testWebView.loadData(newhtml_code,"text/html", "base64");
like image 81
Sagar Dangi Avatar answered Dec 09 '22 17:12

Sagar Dangi


Try calling

String encodedHtml = Base64.encodeToString(html_code.getBytes(), Base64.NO_PADDING);

webview.getSettings().setJavaScriptEnabled(true);

before

webview.loadData(encodedHtml , "text/html", "base64");

like below

    String html_code= "<html><body>Your Actualtext.</body></html>";
    String encodedHtml = Base64.encodeToString(html_code.getBytes(), Base64.NO_PADDING);
 webview.getSettings().setJavaScriptEnabled(true);
    webview.loadData(encodedHtml , "text/html", "base64");

for more details refer to this link

like image 24
Amin Pinjari Avatar answered Dec 09 '22 17:12

Amin Pinjari