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

懵懂的女人 提交于 2019-12-11 04:17:13

问题


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.


回答1:


Use This code it will work.

String newhtml_code = Base64.encodeToString(html_code.getBytes(), Base64.NO_PADDING);
        testWebView.loadData(newhtml_code,"text/html", "base64");



回答2:


Now it is working after performing base-64 encoding to string html_code.

Solved issue by passing html_code string as per given instruction in docs




回答3:


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




回答4:


manifest file in

 android:usesCleartextTraffic="true"

and

 WebSettings settings = wb_webview.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);
String html_code = "html code";
wb_webview.loadData(Base64.encodeToString(html_code.getBytes(), Base64.NO_PADDING) , "text/html", "base64");


来源:https://stackoverflow.com/questions/58182412/webviews-loaddata-is-not-working-in-android-10-0-q

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!