ERR_UNKNOWN_URL_SCHEME appears when WebView clicks on the link

It is found that the link shown in the picture in the problem description is a custom protocol of Baidu APP, and since WebView only supports protocols such as http and https , when encountering such a custom protocol, WebView does not know how to parse it.

Set up webViewClient and filter the intercepted url in the shouldOverrideUrlLoading method:

mWebView.webViewClient = object: WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
                return if(url!!.startsWith("http:")||url.startsWith("https:")){
                //对http或者https协议的链接进行加载
                    view!!.loadUrl(url)
                    true
                }else{
                //这里需要捕捉异常,因为如果没有安装相关的APP会有类找不到的异常
                    try {
                    //启动对应协议的APP
                        val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
                        startActivity(intent)
                    }catch (e:Exception){
                    }
                    true
                }
            }
        }

Guess you like

Origin blog.csdn.net/ffffffff8/article/details/109388657