Skip to content Skip to sidebar Skip to footer

How To Intercept Url Loads In WebView (android)?

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() metho

Solution 1:

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.


Solution 2:

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

Post a Comment for "How To Intercept Url Loads In WebView (android)?"