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

前端 未结 6 1293
暖寄归人
暖寄归人 2021-01-19 06:16

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.

相关标签:
6条回答
  • 2021-01-19 06:57

    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");
    
    0 讨论(0)
  • 2021-01-19 07:07

    I facing the same issue and fix it by using loadDataWithBaseURL() instead loadData() method

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

    solution:

    mWebView.loadDataWithBaseURL(null,mHtml,"text/html", "UTF-8", null);
    
    0 讨论(0)
  • 2021-01-19 07:09

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

    Issue resolved by passing html_code string as per given instruction in docs

    0 讨论(0)
  • 2021-01-19 07:10

    I came up with another solution by using loadDataWithBaseURL

    e.g.

    webView.loadDataWithBaseURL(null, html, "text/html", null, null)
    

    It should use less CPU and memory resource as no need Base64 calculation and storing.

    0 讨论(0)
  • 2021-01-19 07:11

    Use this code, it will work.

    String newhtml_code = Base64.encodeToString(html_code.getBytes(), Base64.NO_PADDING);
            testWebView.loadData(newhtml_code,"text/html", "base64");
    
    0 讨论(0)
  • 2021-01-19 07:15

    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

    0 讨论(0)
提交回复
热议问题