shouldOverrideUrlLoading in WebView for Android not running
After some research I conclude that despite what most of the tutorials out there say, shouldOverrideUrlLoading()
does not get called when:
You load a URL like
loadUrl("http://www.google.com");
The browser redirects the user automatically via an HTTP Redirect. (See the comment from @hmac below regarding redirects)
It does however, get called when you you click on a link inside a webpage inside the webview. IIRC the twitter authorization uses an HTTP Redirect.. Bummer, this would be helpful if it worked how all the tutorials say it does. I think this is from a very old version the Android API...
You might want to consider overriding the onProgressChanged
method of a WebChromeClient
like here: How to listen for a WebView finishing loading a URL? or the onPageFinished()
method of the WebViewClient
.
webview shouldOverrideUrlLoading not working
return true;
instead
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
WebView shouldOverrideUrlLoading() not called for invalid links
You're probably using the KitKat WebView. This is a known issue (I think it's outlined in the migration guide) where URLs that can't be resolved against the base URL are dropped on the floor (you won't get any callbacks for them, neither shouldOverrideUrlLoading nor onPageStarted).
The problem is that your base URL is a data url, so you're trying to resolve '/q?type=short' against 'data:text/html,...' which doesn't make much sense and so the whole attempt to navigate to the URL gets ignored.
This was different for the pre-KK WebView which used KURL instead of GURL for URL processing. GURL is generally more strict (and more secure) than KURL, which is the cause for some incompatibility between the two WebView versions.
Related Topics
Custom Listview Fast Scrollbar in Android
Android Volley Imageloader - Bitmaplrucache Parameter
Android Studio 3.1 Edittext Stackoverflowerror
Isvalidfragment Android API 19
Mobile Chrome Fires Resize Event on Scroll
How to Play .Mp4 Video in Videoview in Android
Android: Wait on User Input from Dialog
How to Add Radio Button Dynamically as Per The Given Number of Counts
Android Active Link of Url in Textview
Android How to Wait Until a Service Is Actually Connected
Commitallowingstateloss() in Fragment Activities
Make Android Webview Not Store Cookies or Passwords
How to Detect If Changes Were Made in The Preferences
Android V21 Theme.Appcompat Color Accent Is Ignored, No Padding on Dialogs
Zipalign - Command Not Found - MAC Terminal
Eclipse: Won't Let Me Use Android Sdk, Wrongly Claims My Adt Is Out of Date