Err_Unknown_URL_Scheme Android Kotlin

时间:2019-02-27 23:47:45

标签: android html webview

我是Android和Kotlin的新手。当我创建自己的HTML页面时。我加入了

之类的链接

<a href='tel:8787878787'>Call our customer service</a>

最后发现ERR_UNKNOWN_URL_SCHEME错误。 我在Java中找到了答案。

Android WebView err_unknown_url_scheme

但是我要在科特林。

请帮助

1 个答案:

答案 0 :(得分:1)

您应该重写shouldOverrideUrlLoading()方法。该方法已被弃用,因此也请覆盖新方法。

inner class MyWebViewClient : WebViewClient()
{
    override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean
    {
        if(URLUtil.isNetworkUrl(url))
        {
            return false
        }
            try
            {
            val shareIntent= Intent()
            shareIntent.action=Intent.ACTION_VIEW
            shareIntent.data= Uri.parse(url)
            startActivity(shareIntent)
            }
            catch(e: ActivityNotFoundException)
            {Toast.makeText(this@MainActivity, "Appropriate app not found", Toast.LENGTH_LONG).show()
                Log.e("AndroidRide",e.toString())
            }
        return true
    }
    @RequiresApi(Build.VERSION_CODES.N)
    override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean
    {
        val url=request?.url.toString()
        if(URLUtil.isNetworkUrl(url))
        {
            return false
        }
        try
        {
            val shareIntent= Intent()
            shareIntent.action=Intent.ACTION_VIEW
            shareIntent.data= Uri.parse(url)
            startActivity(shareIntent)
        }            catch(e: ActivityNotFoundException)
        {Toast.makeText(this@MainActivity, "Appropriate app not found", Toast.LENGTH_LONG).show()
            Log.e("AndroidRide",e.toString())
        }
        return true

    }

Err Unknown URL scheme Example