在使用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) {
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