Android - Open target _blank links in WebView with external browser

前端 未结 5 1393
忘掉有多难
忘掉有多难 2020-12-01 06:37

I build a WebView which displays a website. The website contains links without a target=\"_blank\" attribute and some with it.

I need to op

5条回答
  •  情歌与酒
    2020-12-01 07:05

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

提交回复
热议问题