I have an article app, I am showing articles in WebView
. In Android version 9.0 (API-29) this WebView
is not working. The app shows NOTHING in my article Activity.
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");
As a result, how can I solve this problem?
The Android system webview custom cache file has been deprecated and removed in Android 13. New apps and any app updates will now use the operating system default cache location.
Enable JavaScript JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView . You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.
The loadUrl() and loadData() methods of Android WebView class are used to load and display web page.
loadUrl when you say loadUrl. From documentation, only difference between them is, loadURL renders a webkit having a url that you set. On the other hand, loadData renders webkit, that source code comes from a parameter, and baseURL is also a parameter.
I solved my problem, the problem occurs in Smartphones that has latest Chrome.
SOLUTION:
Do not use
mWebview.loadData
method, instead use
mWebview.loadDataWithBaseURL
As a result my solution is:
mWebview.loadDataWithBaseURL(null,htmlContent,"text/html", "utf-8", null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With