Tag Archives: Android WebView loading HTTP error

Android WebView loading HTTP error [How to Solve]

After android9.0, WebView can’t load the link starting with HTTP, or an error is reported.

Solution:

1. Add android:usesCleartextTraffic = true in the Application tag of AndroidManifest;

2. Set in webclient

webView.webViewClient = object : WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
                if (url.startsWith("http://") || url.startsWith("https://")) {
                    webView.loadUrl(url)
                    return true
                }
                return true
            }
}