i have a webview where i load an url and when i click the webview i want to open the link in the default browser.I tried to set the WebViewClient and override shouldOverrideUrlLoading(WebView view, String url) method
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.e("BaseFragment", "shouldOverrideUrlLoading " + url); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); return false; } but it is not called by the webview. Any other ideas to do this?
BaseFragment is an abstract class where i have the following WebViewClient:
protected WebViewClient mAddWebViewClient = new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { float scale = addTopWebView.getHeight() / 170f; addTopWebView.setInitialScale((int) (scale * 100f)); String js = "javascript:(function(){" + "document.getElementsByTagName('div')[0].style.height = 'auto';" + "document.getElementsByTagName('div')[0].style.width = 'auto';" + "})()"; view.loadUrl(js); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.e("BaseFragment", "shouldOverrideUrlLoading " + url); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); return true; } }; And other fragments which extend this BaseFragment have some webviews and there in onViewCreated method i set the webviewclient:
myWebView.getSettings().setJavaScriptEnabled(true); addTopWebView = myWebView; myWebView.setWebViewClient(mAddWebViewClient);
trueto avoid loading the page also in the webview, but that is not relevant for now). Can you post more code? (creating the webview, setting the WebViewClient...)