1

On a HTC Evo running Android 2.3.5, overrriden shouldOverrideUrlLoading() is never called. The exact same code works well on a Samsung Galaxy running Android 2.3.6.

so far, I have tried overriding onPageStarted() and onPageFinished(). I do not see the URL in these methods.

My intent is to provide custom activities for mailto: and tel: links present in the page. Any ideas on how I can make this work if shouldOverrideUrlLoading() is never hit?

I have already looked at similar questions on stackoverflow and elsewhere, haven't found anything relevant.

Chaitanya
  • 2,039
  • 4
  • 25
  • 32
  • [took from ](http://stackoverflow.com/questions/9670136/shouldoverrideurlloading-gets-called-only-for-some-webpages). The problem seemed to be js function setTimeout(fn, millis). You have write a js function that overrides it and then recreate the behaviour of this function in your Android code (using JavascriptInterface) as it fits best for your app. It's a lot of work which depends of your app functionality, but it works. The idea is overriding setTimeout then call a method from android code who sleeps the thread for how many millis were in the initial calling of the setTimeout in js.. – Maxim Shoustin Oct 27 '12 at 00:29
  • Thanks for your comment. I'll give it a try; but Javascript might not be an acceptable solution. I am also looking at http://stackoverflow.com/questions/5116909/how-i-can-get-onclick-event-on-webview-in-android – Chaitanya Oct 28 '12 at 15:46

1 Answers1

4

shouldOverrideUrlLoading() doesn't work only on some Android versions, like 2.1 or 2.3.6 but it works fine on 2.3.3, 2.3.5, 4.0.2 or 4.0.3.

If you need to handle clicking on a link on webview, you must use shouldOverrideUrlLoading() method. If you only need to handle loading a webpage, you should use onPageStarted().

This is android developer link: https://developer.android.com/guide/webapps/migrating.html

  • Note: Ex: we have 2 links on Webpage.

    1. <a href="http://www.w3schools.com/">Visit W3Schools!</a>
    2. <a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>

shouldOverrideUrlLoading() is only called when user click on link "1". and it isn't called when user click on link "2"

public void onPageStarted(WebView view, String url, Bitmap favicon) {

    if (url.contains("success")) {
        Intent intent = new Intent(WebviewActivity.this, OrderConfirmActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    } else {
        super.onPageStarted(view, url, favicon);
    }
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Anh Duy
  • 1,145
  • 15
  • 25