Error WebView.loadData (EWLD)

I have an article app that displays articles in WebView format. However, in Android 9.0 (API-29), WebView is not working so my app does not display anything on the Activity.

My code looks something like this:

mWebView.setVisibility(View.VISIBLE);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setMinimumFontSize(14);

String htmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
   + "<head>"
   + "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />"
   + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>"
   + "<style type=\"text/css\">body{color: #525252;} img {max-width: 100%; height: auto}</style>"
   + "</head>"
   + item.getContent() //content of item
   + "";

mWebView.loadData(htmlContent, "text/html; charset=utf-8", "UTF-8");

Solutip

I solved the problem, which occurs on Smartphone with the latest version of Chrome, then do not use:

mWebview.loadData

Instead of using

mWebview.loadDataWithBaseURL

So, my solution is:

mWebview.loadDataWithBaseURL(null,htmlContent,"text/html", "utf-8", null);

done!


Post a Comment

Previous Next

نموذج الاتصال