How to intercept url loads in WebView (android)?

后端 未结 2 1215
清酒与你
清酒与你 2020-12-17 19:35

I have a WebView in which I load a page with a custom link (like app://action). I registered the url schemes in the manifest file and when I click on the link, the onResume(

相关标签:
2条回答
  • 2020-12-17 20:29

    Use WebViewClient.shouldOverrideUrlLoading instead.

    public boolean shouldOverrideUrlLoading(WebView view, String url){
        // handle by yourself
        return true; 
    }
    

    WebViewClient Reference

    Updates: Method shouldOverrideUrlLoading(WebView, String) is deprecated in API level 24. Use shouldOverrideUrlLoading(WebView, WebResourceRequest) instead.

    0 讨论(0)
  • 2020-12-17 20:32

    But it must return false otherwise, so:

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url){
        if(url.startsWith(myString){
            // handle by yourself
            return true;
        } 
        // ...
        return false;
    }
    
    0 讨论(0)
提交回复
热议问题