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;
    }
});

I also have the same problem and now I've found the solution.

You also need to use WebChromeClient.You can see this and this . And you can set a WebViewClient to the new WebView and override the shouldOverrideUrlLoading method, then you can get the url and do whatever you want here. If you don't set the WebViewClient, I think it should works too. In my case I want to get the url so I set a WebViewClient to the new WebView.

By the way, if you remove the old webview then when you come back form the browser,the webview is blank. So I retained the webview and added a new one but set the visibility to "gone".


I faced same problem. I wanted to open my web sites pages inside the application and rest all the pages should be open in Default Browser. I used one technique. If URL contains my website name, then I opened it in WebView and rest all the websites opened in Default browser.

Find Below code, I hope It would be useful for all who faced such problems.

private class MyBrowser extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.contains("/internetgeeks")) {
            browser.loadUrl(url);
            return false;
        } else {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);
            return true;
        }
    }
}