Issue
The shouldOverrideUrlLoading() never gets called if I click a link within the webview. (It doesn't show the toast or logs anything). I've tried also onPageFinished and it doesn't get called too. I read other posts where users are having problems that this is not called only sometimes, but in my case it's completely ignored.
webview = new WebView(MyActivity.this);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setDisplayZoomControls(false);
webview.loadData(Html.getHtml(), "text/html", "UTF-8");
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
new M("shouldOverrideUrlLoading",getApplicationContext());
Log.v("ESSE3", "shouldOverrideUrlLoading()");
System.out.println(url);
System.out.println(Html.getHtml());
webview.loadData(Html.getHtml(), "text/html", "UTF-8");
return true;
}
});
webview.setWebViewClient(new WebViewClient());
setContentView(webview);
Tried with/without javascript enabled or returning true or false within the method.
Solution
You call setWebViewClient() twice. Once with your overriding method and once with an empty WebViewClient! That's why your method isn't getting called.
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
....
}
});
webview.setWebViewClient(new WebViewClient());
Answered By - David Wasser
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.