注意:里面重写的两个shouldOverrideUrlLoading()方法是针对不同的版本。
webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { LogUtil.log(TAG, "打电话的1连接href_url=" + request.getUrl()); String tag = "tel:"; if (request.getUrl() != null && request.getUrl().toString().contains(tag)) { String mobile = request.getUrl().toString().substring(request.getUrl().toString().lastIndexOf(":") + 1); Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mobile)); startActivity(intent); return true; } } //返回false,意味着请求过程里,不管有多少次的跳转请求(即新的请求地址),均交给webView自己处理,这也是此方法的默认处理 //返回true,说明你自己想根据url,做新的跳转,比如在判断url符合条件的情况下,我想让webView加载http://ask.csdn.net/questions/178242 return true; } @Override public boolean shouldOverrideUrlLoading(WebView view, String href_url) { LogUtil.log(TAG, "打电话的连接href_url=" + href_url); //点击的打电话的超链接 String tag = "tel:"; if (href_url.contains(tag)) { String mobile = href_url.substring(href_url.lastIndexOf(":") + 1); Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mobile)); startActivity(intent); return true; } return super.shouldOverrideUrlLoading(view, url); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); } });