WebViewClient
을 사용하는 코드에 WebView
이 있습니다. 내 CustomWebViewClient
파일에서 다양한 오류 메서드를 재정의했습니다.Android WebViewClient가 적절한 오류를 반환하지 않음
public class CustomWebViewClient extends WebViewClient {
@SuppressWarnings("deprecation")
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onReceivedHttpError(
WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
}
}
이제 WebView에서 다양한 유형의 오류를 처리하고 싶습니다. 나는 다음과 같은 시나리오를 시도했다.
1) 로컬 HTML "file : ///android_asset/main.html"이 존재하지 않습니다.
-이 시나리오에서는 첫 번째 방법, 즉 OnReceivedError()
에 대한 콜백을 받고 있습니다.
2) 웹상에서 호스팅되는 html 페이지, 즉 http://help.websiteos.com/websiteos/example_of_a_simple_html_page.ht을로드하십시오. 이 html도 존재하지 않습니다. 하지만이 경우에는 오류 메서드에 대한 콜백을 얻지 못하고 있습니다. 크롬에 검사하는 동안
, 나는가 GET 다음과 같은 오류를 얻고있다 http://help.websiteos.com/websiteos/example_of_a_simple_html_page.ht 404 (찾을 수 없음), 자원을 사용할 수 없음을 보여줍니다 명확하게한다. 그러면 WebView가 오류에 대한 콜백을 반환하지 않는 이유는 무엇입니까?
두 경우 모두 사용할 수없는 리소스를 요청하고 있습니다. 하지만 첫 번째 시나리오에서만 오류 콜백이 발생합니다.
주셔서 감사합니다. 그러나 마쉬멜로우 아래에서 http 오류를 얻을 수있는 방법이 있습니까? – thedarkpassenger