webviewclient
Android – Open target _blank links in WebView with external browser
After visiting the above links, I come up with this code and hope this helps. wv.getSettings().setSupportMultipleWindows(true); wv.setWebChromeClient(new WebChromeClient() { @Override public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, android.os.Message resultMsg) { WebView.HitTestResult result = view.getHitTestResult(); String data = result.getExtra(); Context context = view.getContext(); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data)); context.startActivity(browserIntent); return false; } });
Intercept and override HTTP requests from WebView
Try this, I’ve used it in a personal wiki-like app: webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.startsWith(“foo://”)) { // magic return true; } return false; } });
Are WebViewClient and WebChromeClient mutually exclusive?
You certainly can use both, they just have different functions. Setting your own custom WebViewClient lets you handle onPageFinished, shouldOverrideUrlLoading, etc., WebChromeClient lets you handle Javascript’s alert() and other functions. Just make your own class, for example: public class MyWebChromeClient extends WebChromeClient { //Handle javascript alerts: @Override public boolean onJsAlert(WebView view, String url, String message, … Read more
Enabling general JavaScript in WebViewClient
I don’t know what your exact problem is, but i can enable the JavaScript and a custom WebViewclient without any problem: WebView vistaWeb = (WebView) findViewById(R.id.webview); vistaWeb.setWebChromeClient(new MyCustomChromeClient(this)); vistaWeb.setWebViewClient(new MyCustomWebViewClient(this)); vistaWeb.clearCache(true); vistaWeb.clearHistory(); vistaWeb.getSettings().setJavaScriptEnabled(true); vistaWeb.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
What’s the difference between setWebViewClient vs. setWebChromeClient?
From the source code: // Instance of WebViewClient that is the client callback. private volatile WebViewClient mWebViewClient; // Instance of WebChromeClient for handling all chrome functions. private volatile WebChromeClient mWebChromeClient; // SOME OTHER SUTFFF……. /** * Set the WebViewClient. * @param client An implementation of WebViewClient. */ public void setWebViewClient(WebViewClient client) { mWebViewClient = client; … Read more
Android webview launches browser when calling loadurl
Answering my question based on the suggestions from Maudicus and Hit. Check the WebView tutorial here. Just implement the web client and set it before loadUrl. The simplest way is: myWebView.setWebViewClient(new WebViewClient()); For more advanced processing for the web content, consider the ChromeClient.