Android 网页无法打开 net:ERR_UNKNOWN_URL_SCHEME

web.setWebViewClient(new MyWebViewClient());


/**
 * 防止有 URL Scheme 跳转协议类型的url 导致webView加载网页失败
 * */
private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url == null) return false;
        if (url.startsWith("http:") || url.startsWith("https:") ){
            view.loadUrl(url);
            return false;
        }else{
            try{
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                mContext.startActivity(intent);
            }catch (Exception e){
                //ToastUtils.showShort("暂无应用打开此链接");
            }
            return true;
        }
    }
}

你可能感兴趣的:(android,webview)