eros icon indicating copy to clipboard operation
eros copied to clipboard

setWebViewClient 重写拦截出现问题 没有进入shouldOverrideUrlLoading

Open LingCn opened this issue 5 years ago • 0 comments

mWeb.setWebViewClient(new MyWebViewClient(this){ //加载错误的时候会回调 @Override public void onReceivedError(WebView webView, int i, String s,final String s1) { Log.e("---log","onReceivedError i"+i); Log.e("---log","onReceivedError s"+s);

            if (s1.startsWith("http")||s1.startsWith("https")||s1.startsWith("ftp")){
                super.onReceivedError(webView, i, s, s1);
            } else {
                Log.e("---log","onReceivedError"+s1);
                try {
                    Log.e("---log","try"+s1);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Intent intent =new Intent();
                            intent.setAction(Intent.ACTION_VIEW);
                            intent.setData(Uri.parse(s1));
                            startActivity(intent);
                        }
                    });

                }catch (Exception e){
                    Log.e("---log","catch"+s1);
                    e.printStackTrace();
                }
            }
        }
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.e("---log",url);
            if (url.startsWith("http")||url.startsWith("https")||url.startsWith("ftp")){
                return super.shouldOverrideUrlLoading(view, url);
            } else {
                Log.e("---log",url);
                try {
                    Intent intent =new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(url));
                    startActivity(intent);
                }catch (Exception e){
                    Log.e("---log","shouldOverrideUrlLoading    catch");
                    e.printStackTrace();
                }

                return true;
            }
        }
    });

LingCn avatar Oct 18 '19 04:10 LingCn