Java Code Examples for android.webkit.WebResourceResponse#getStatusCode()

The following examples show how to use android.webkit.WebResourceResponse#getStatusCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebPlayerView.java    From unity-ads-android with Apache License 2.0 6 votes vote down vote up
@TargetApi(21)
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
	if (shouldCallSuper("onReceivedHttpError")) {
		super.onReceivedHttpError(view, request, errorResponse);
	}
	if (shouldSendEvent("onReceivedHttpError")) {
		String url = "";
		if (request != null && request.getUrl() != null) {
			url = request.getUrl().toString();
		}

		int statusCode = -1;
		String reasonPhrase = "";
		if (errorResponse != null) {
			statusCode = errorResponse.getStatusCode();
			reasonPhrase = errorResponse.getReasonPhrase();
		}

		WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.WEBPLAYER, WebPlayerEvent.HTTP_ERROR, url, reasonPhrase, statusCode, viewId);
	}
}
 
Example 2
Source File: CommonRefreshWebViewActivity.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
    super.onReceivedHttpError(view, request, errorResponse);
    String errRespStr = "";
    if (errorResponse != null) {
        if (Util.isCompateApi(21)) {
            errRespStr += "status code =" + errorResponse.getStatusCode() + " | reason : " + errorResponse.getReasonPhrase();
        }
    }
    e(null, "--> onReceivedHttpError() request url = " + request.getUrl() + "  errRespStr = " + errRespStr);
}
 
Example 3
Source File: ByWebTools.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
/**
 * Android 6.0以上处理方法:
 * 重写WebViewClient的onReceivedHttpError()方法,判断错误码来处理;
 */
public static void handleReceivedHttpError(WebView webView, WebResourceResponse errorResponse) {
    // 这个方法在 android 6.0才出现
    int statusCode = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        statusCode = errorResponse.getStatusCode();
    }
    if (404 == statusCode || 500 == statusCode) {
        String mErrorUrl = "file:///android_asset/404_error.html";
        webView.loadUrl(mErrorUrl);
    }
}
 
Example 4
Source File: ByWebViewClient.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
@Override
    public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
        super.onReceivedHttpError(view, request, errorResponse);
//        WebTools.handleReceivedHttpError(view, errorResponse);
        // 这个方法在 android 6.0才出现
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            int statusCode = errorResponse.getStatusCode();
            if (404 == statusCode || 500 == statusCode) {
                String mErrorUrl = "file:///android_asset/404_error.html";
                view.loadUrl(mErrorUrl);
            }
        }
    }
 
Example 5
Source File: WebTools.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
/**
 * Android 6.0以上处理方法:
 * 重写WebViewClient的onReceivedHttpError()方法,判断错误码来处理;
 */
public static void handleReceivedHttpError(WebView webView, WebResourceResponse errorResponse) {
    // 这个方法在 android 6.0才出现
    int statusCode = 0;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        statusCode = errorResponse.getStatusCode();
    }
    if (404 == statusCode || 500 == statusCode) {
        String mErrorUrl = "file:///android_asset/404_error.html";
        webView.loadUrl(mErrorUrl);
    }
}
 
Example 6
Source File: MyWebViewClient.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
@Override
    public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
        super.onReceivedHttpError(view, request, errorResponse);
//        WebTools.handleReceivedHttpError(view, errorResponse);
        // 这个方法在 android 6.0才出现
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            int statusCode = errorResponse.getStatusCode();
            if (404 == statusCode || 500 == statusCode) {
                String mErrorUrl = "file:///android_asset/404_error.html";
                view.loadUrl(mErrorUrl);
            }
        }
    }