【问题标题】:Redirect to android webview app when clicked on a link单击链接时重定向到 android webview 应用程序
【发布时间】:2020-07-15 07:04:17
【问题描述】:

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

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

【问题讨论】:

    标签: android android-webview


    【解决方案1】:

    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)
                }
            }
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-22
      • 2010-12-06
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      • 1970-01-01
      • 2016-12-16
      相关资源
      最近更新 更多