Android如何直接链接到默认浏览器
原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/questions/1995
问题描述:
我在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语句。