Reputation: 406
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.
Upvotes: 2
Views: 4135
Reputation: 95626
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());
Upvotes: 8