Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LingCn opened this issue Oct 18, 2019 · 0 comments

Comments

@LingCn
Copy link

LingCn commented Oct 18, 2019

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;
            }
        }
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant