android - WebView shouldOverrideUrlLoading() not called for invalid links -


there 2 types of links in html file:

(1) normal link http://www.bbb.com/q?type=normal (2) short link /q?type=short. 

for first kind, load url. second kind, should prepend fixed address http://www.abc.com before loading url.

i trying overriding shouldoverrideurlloading() function in webviewclient. function doesn't gets called second type of link. tried prepending "http://www.abc.com" second type of links in html file. function called when click second kind of link.

i think what's happening webview first check if link valid url. if valid function gets called. right? how can solve this? in advance.

        contentwebview = new webview(context);          webviewclient = new webviewclient() {             @override             public void onpagestarted(webview view, string url, bitmap favicon) {                 super.onpagestarted(view, url, favicon);             }              @override             public boolean shouldoverrideurlloading(webview view, string url) {                 // string not in logger.                 log.d(tag, "here!");                 intent intent = new intent(intent.action_view, uri.parse(url));                 context.startactivity(intent);                 return true;             }              @override             public void onpagefinished(webview view, string url) {                 super.onpagefinished(view, url);                 if (hosted) {                     contentwebview.setvisibility(visible);                 } else {                     summarytextview.setvisibility(visible);                     articlelinkbutton.setvisibility(visible);                 }                  progressbar.setvisibility(view.gone);             }         };          contentwebview.setwebviewclient(webviewclient);         contentwebview.getsettings().setjavascriptenabled(true);         contentwebview.loaddata(fullstring, "text/html", "utf-8");         contentwebview.setvisibility(gone); 

more on this:

i tried changing

contentwebview.loaddata(fullstring, "text/html", "utf-8"); 

to

contentwebview.loaddatawithbaseurl("http://www.abc.com", fullstring, "text/html", "utf-8", null); 

then function gets called.

if change short link full link in html string manually. function gets called.

so think happening: webview checks if link url valid. when url valid shouldoverrideurlloading() called.

you're using kitkat webview. known issue (i think it's outlined in migration guide) urls can't resolved against base url dropped on floor (you won't callbacks them, neither shouldoverrideurlloading nor onpagestarted).

the problem base url data url, you're trying resolve '/q?type=short' against 'data:text/html,...' doesn't make sense , whole attempt navigate url gets ignored.

this different pre-kk webview used kurl instead of gurl url processing. gurl more strict (and more secure) kurl, cause incompatibility between 2 webview versions.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -