Android モニタリング WebView のロードに失敗しました

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) {
    
    
                int errorCode = error.getErrorCode();
                String errorMessage = error.getDescription().toString();
                Log.i("CustomWebViewClient", "onReceivedError  errorCode : " + errorCode + " errorMessage : " + errorMessage);
            }
        }
 
        @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) {
    
    
                Log.i("CustomWebViewClient", "onReceivedError  errorCode : " + errorCode + " description : " + description);
            }
        }
    }

:WebViewClientのonReceivedError()メソッドはAndroidのバージョンに応じたバージョン互換が必要であり、Android 6.0以上の場合は上記メソッドをコールバックし、6.0未満の場合は以下の関数をコールバックしてください。
以下は 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;

Guess you like

Origin blog.csdn.net/weixin_42504805/article/details/132626769