由于Webview只能识别http、https开头的网页,导致如果打开不是这两个开头的网址会出现:加载网页出现(“找不到网页net:err_unknown_url_scheme”)的错误。 不过不要紧张,在shouldOverrideUrlLoading里写入不是http、https开头的网址的情况处理办法就可解决问题:
mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if(url == null) return false; try { if (url.startsWith("http:") || url.startsWith("https:")) { view.loadUrl(url); return true; } else { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } } catch (Exception e) { //防止crash (如果手机上没有安装处理某个scheme开头的url的APP, 会导致crash) return false; } } });