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.

publicbooleanshouldOverrideUrlLoading(WebView view, String url){
    // handle by yourselfreturntrue; 
}

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:

@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url){
    if(url.startsWith(myString){
        // handle by yourselfreturntrue;
    } 
    // ...returnfalse;
}

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