- mWebView.setWebViewClient(new WebViewClient(){
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- if( url.startsWith("http:") || url.startsWith("https:") ) {
- return false;
- }
- try{
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- startActivity( intent );
- }catch(Exception e){}
- return true;
- }
- });
这里必须要做try catch,因为url可能不是合法的,或者无法打开,try catch后就能正常访问网页了