• WebView 错误码整理


    在使用WebView中,我们不可避免的会接触到WebView加载失败的异常处理的需求,这时候,需要我们监听失败的方法也就是onReceivedError方法:

    public class CustomWebViewClient extends WebViewClient {
    
        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (error.getErrorCode() == ERROR_HOST_LOOKUP) {
                    view.loadUrl("about:blank");
                }
            }
        }
    
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                if (errorCode == ERROR_HOST_LOOKUP) {
                    view.loadUrl("about:blank");
                }
            }
        }
    }
    
    

    下面是errorCode的列举

    /** Generic error */
    public static final int ERROR_UNKNOWN = -1;
    /** Server or proxy hostname lookup failed */
    public static final int ERROR_HOST_LOOKUP = -2;
    /** Unsupported authentication scheme (not basic or digest) */
    public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;
    /** User authentication failed on server */
    public static final int ERROR_AUTHENTICATION = -4;
    /** User authentication failed on proxy */
    public static final int ERROR_PROXY_AUTHENTICATION = -5;
    /** Failed to connect to the server */
    public static final int ERROR_CONNECT = -6;
    /** Failed to read or write to the server */
    public static final int ERROR_IO = -7;
    /** Connection timed out */
    public static final int ERROR_TIMEOUT = -8;
    /** Too many redirects */
    public static final int ERROR_REDIRECT_LOOP = -9;
    /** Unsupported URI scheme */
    public static final int ERROR_UNSUPPORTED_SCHEME = -10;
    /** Failed to perform SSL handshake */
    public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;
    /** Malformed URL */
    public static final int ERROR_BAD_URL = -12;
    /** Generic file error */
    public static final int ERROR_FILE = -13;
    /** File not found */
    public static final int ERROR_FILE_NOT_FOUND = -14;
    /** Too many requests during this load */
    public static final int ERROR_TOO_MANY_REQUESTS = -15;
    
  • 相关阅读:
    钻进 Linux 内核看个究竟
    如何监控 Linux 服务器状态?
    树莓派使用 OLED 屏显示图片及文字
    动态代理学习(二)JDK动态代理源码分析
    动态代理学习(一)自己动手模拟JDK动态代理
    SpringCloudGateWay学习 之 从函数式编程到lambda
    leetCode刷题 | 两数相加
    leetCode刷题 | 两数之和
    数据结构 | 再也不怕被问栈跟队列了
    算法 | 链表的应用,缓存失效算法
  • 原文地址:https://www.cnblogs.com/renhui/p/7940879.html
Copyright © 2020-2023  润新知