Android webview capture link clicks

This can be done

you have to set a WebViewClient to your WebView. this is how to do that.

WebView webView;//make sure to initialize  
webView.setWebViewClient(webViewClient);

WebViewClient webViewClient= new WebViewClient(){
    @Override
    public boolean shouldOverrideUrlLoading(WebView  view, String  url){
        return true;
    }
    @Override
    public void onLoadResource(WebView  view, String  url){
        if( url.equals("http://yoururl.com") ){
            // do something
        }
    }
}

use this code it's work for me

webview.setWebViewClient(new WebViewClient()
        {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                return true;
            }
        });

You can do something like this:

WebView myWebView  = (WebView) findViewById(R.id.yourWebView);
myWebView.setWebViewClient(new MyWebViewClient());
myWebView.loadUrl("yourLink");

but then don't forget to create a WebViewClient:

public class MyWebViewClient extends WebViewClient {

     @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            return true;
        }
}

Tags:

Android