简体   繁体   中英

How can i make a link to open in browser instead of WebView App

I created a WebView App and it's working fine but there is a link which I want it to open in the default browser instead of that app what can I do.

Add a WebViewClient to your webView (if not already added) and then override shouldOverrideUrlLoading () method:

webView.setWebViewClient(new WebViewClient() {
     @Override
     public boolean shouldOverrideUrlLoading(WebView webview, String url) {
        if (url.contains(myUrl)) {
            Intent intent= new Intent(Intent.ACTION_VIEW, myUrl);
            context.startActivity(intent);
            return true;
        } else {
            return super.shouldOverrideUrlLoading(webview, url);
        }
     }      
}

This way your are telling your webview to not continue loading a specific url . Instead, launch the proper application (mostly a browser) to handle the url .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM