问题
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.
回答1:
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.
<a href="http://www.w3schools.com/">Visit W3Schools!</a><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);
}
}
来源:https://stackoverflow.com/questions/13096103/android-overriding-shouldoverrideurlloading-not-working-on-htc-devices