首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android怎么直接链接到默认浏览器

2013-04-12 
Android如何直接链接到默认浏览器原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/question

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语句。

热点排行