单击链接时重定向至android webview应用程序



我已经在上面构建了一个Android WebView应用程序https://example.com.所以我有一个链接https://example.com/link当从哪里点击时,必须在应用程序中打开,而不是在默认浏览器中打开。

假设我点击了链接https://example.com/link在chrome上,但我希望链接在我的应用程序中打开,即就像亚马逊一样,当点击chrome上的链接时,它会重定向到应用程序。

WebViewClient添加到WebView并覆盖shouldOverrideUrlLoading

Kotlin示例:

binding?.webView?.webViewClient = object : WebViewClient(){
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
request?.url // handle it here and return true or false depend on if you want webview to load it pr you going to handle it your self
return super.shouldOverrideUrlLoading(view, request)
}
}

最新更新