美文网首页Android葵花宝典webview与h5交互大全Android开发
Webview加载网页出现("找不到网页net:err

Webview加载网页出现("找不到网页net:err

作者: 松饼水果十指鱼 | 来源:发表于2017-11-01 13:22 被阅读401次

    由于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;
                    }
                }
            });
    

    相关文章

      网友评论

        本文标题:Webview加载网页出现("找不到网页net:err

        本文链接:https://www.haomeiwen.com/subject/xhawpxtx.html