我的代碼中有WebView
,它使用自定義WebViewClient
。我在我的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也不存在。但在這種情況下,我沒有得到任何回調的錯誤方法。
雖然在Chrome檢查,我收到以下錯誤
GET http://help.websiteos.com/websiteos/example_of_a_simple_html_page.ht 404(未找到),這清楚地表明,資源不可用。那麼爲什麼WebView不會返回任何錯誤回調?
在這兩種情況下,我正在請求一個不可用的資源。但是我只在第一種情況下收到錯誤回調。
感謝您的信息。但是沒有辦法得到棉花糖下面的http錯誤嗎? – thedarkpassenger