Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android webview capture link clicks

Tags:

android

The application i'm developing has a webview, i need to capture webview request click events(eg: click on a link, click on a button, click on a youtube video play button such as...)

like image 678
Kasun Wanniarachchi Avatar asked Jan 03 '13 10:01

Kasun Wanniarachchi


2 Answers

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
        }
    }
}
like image 117
Asanka Senavirathna Avatar answered Oct 13 '22 02:10

Asanka Senavirathna


use this code it's work for me

webview.setWebViewClient(new WebViewClient()
        {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                return true;
            }
        });
like image 44
V.P. Avatar answered Oct 13 '22 00:10

V.P.