Android直接链接到默认浏览器

我在webview中加载了一个 website。当点击一个链接"Full Site",我想开启手机的默认浏览器,如何实现这个功能呢?目前它在web视图中加载了完整的网站。

你需要在 WebView 对象上添加一个 WebViewClient

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new MyWebViewClient());
........

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals("www.mysite.com")) {
           //Load the site into the default browser
             Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
             startActivity(intent);
             return true;
        }
        // Load url into the webview
       return false;
    }
}

如果需要调整 if-statement语句。

参考 WebViewClient,你需要:
1.创建自定义的 webview client
2.重写 shouldOverrideUrlLoading,显示打开浏览器的链接或没打开链接的状态。
3.设置自定义的 webview client 作为默认的webview client

 WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.setWebViewClient(new WebViewClient());