Monday, 10 August 2015

android webview shouldOverrideUrlLoading




This function will be called when user click a link in the page, and the webview will be redirected to show the link.

This function doesn't get called when webview.load().

This function doesn't get called when webview is loading the resources of a page, resources loading doesn't go through this function.

---------

If this function get called:

You can return false; to let your webview component to handle this url e.g. open the new link or download the link.

You can return true; to let your webview component not handle the url, and you should handle it yourself. e.g. downloading.

If you want system bowsers to handle the link, you should not supply WebViewClient.

        webView.setWebViewClient(new WebViewClient() {

            @Override            
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Log.i(TAG, "shouldOverrideUrlLoading url = " + url);
                return false;
            }

        });








No comments:

Post a comment