【问题标题】:Android WebView fails to load entire page because of missing favicon.ico由于缺少 favicon.ico,Android WebView 无法加载整个页面
【发布时间】:2016-10-28 16:46:56
【问题描述】:

我有一个简单的 WebView 用于加载一些 URL。 页面开始加载(index.html、css 文件等 - 我可以在我的 apache 访问日志中看到它) 然后android显示这个错误:

10-28 19:38:17.948 18990-18990/com。 I/chromium:[INFO:CONSOLE(376)]“错误”,来源:http://**************** (376)

所以我在 WebViewClient 中添加了一个错误处理程序,如下所示:

public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
    logger.e("Failed to open page: "
        + errorResponse.getReasonPhrase() + " "
        + request.getUrl().toString());
}

我在 logcat 中看到了这个:

10-28 19:41:28.678 19506-19506/com.mycompany.myapp E/XXXX xxx.xxx.MyWebViewClient: Failed to open page: Not Found http://xxxxxx/favicon.ico

即使图标丢失,相同的 URL 也可以在桌面上正常打开...有没有办法让 WebView 忽略某些错误?

【问题讨论】:

  • 你解决过这个问题吗?

标签: error-handling android-webview favicon


【解决方案1】:

除非您从onReceivedError 调用某些内容,否则尽管出现错误,您的页面仍应继续加载。

您的 apache 记录器可能是问题所在吗?

我自己,我只提供一个用于主框架的连接对话框。

    @Override
    public void onReceivedError(WebView view, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (webResourceRequest.isForMainFrame()) {                    
                Log.d(LOG_TAG, webResourceError.getDescription());
                displayConnectionErrorAlertDialog();
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-21
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 2018-08-19
    • 1970-01-01
    • 2012-07-31
    相关资源
    最近更新 更多