Skip to content Skip to sidebar Skip to footer

Android : Click Link In A Page Within Web View

I have included a web application within android web view , and there is a link in the webpage which opens some other site , when the link is clicked it works fine for the first cl

Solution 1:

I had the experience that shouldOverrideUrlLoading() is not called in certain circumstances. There are a few bugs about this topic on http://code.google.com/p/android/issues like bug number 15827, 9122, 812, 2887

As a workaround try to add the method onPageStarted() and check if you get this call. For me this method is always called even if shouldOverrideUrlLoading() was not called before.

Solution 2:

onPageStarted worked for me. Had to tweak it a bit, as that method is called when the webview is first rendered too, and I wanted to only execute it on the onClick of the banner's javascript.

I was simulating a banner with a custom page, so when the ad.html was being rendered, I avoided the startActivity. Otherwise, it launches the new browser window.

WebViewClient newWebClient = newWebViewClient() {
        @OverridepublicvoidonPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stubsuper.onPageStarted(view, url, favicon);
            if(!url.equals("http://xxxx.ad.html"))
            view.getContext().startActivity(newIntent(Intent.ACTION_VIEW, Uri.parse(url)));
        }
    };

Solution 3:

Try to append the System parameter pattern in url before you load that, something like.

Stringurl="http://xxxx.ad.html?t="+System.nanoTime();

and in your shouldOverrideUrlLoading() method remove the query part (in a very first line).

int idx;
if ((idx = url.indexOf("?")) != -1) {
    url = url.substring(0, idx);
}

Post a Comment for "Android : Click Link In A Page Within Web View"