禁用Android WebView/WebViewClient启动的favicon.ico请求 [英] Disable Android WebView/WebViewClient Initiated favicon.ico Request
本文介绍了禁用Android WebView/WebViewClient启动的favicon.ico请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我调用WebView.loadUrl()时,如何禁止Android WebView/WebViewClient发送对favicon.ico的请求?我可以看到通过CharlesProxy对请求进行概要分析时正在进行呼叫.
How can I disable the Android WebView/WebViewClient from sending out a request for favicon.ico when I call WebView.loadUrl()? I can see the call being made while profiling requests via CharlesProxy.
我不拥有要在WebView中显示的HTML内容.我的研究从服务器方面获得了许多变通办法的结果,但这些对我不起作用.
I do not own the HTML content that I am displaying in the WebView. My research has turned up a lot of results on workarounds from the server side but these won't work for me.
推荐答案
对我来说,完整的解决方案是:
for me the complete solution was:
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if(url.toLowerCase().contains("/favicon.ico")) {
try {
return new WebResourceResponse("image/png", null, null);
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
@Override
@SuppressLint("NewApi")
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
if(!request.isForMainFrame() && request.getUrl().getPath().endsWith("/favicon.ico")) {
try {
return new WebResourceResponse("image/png", null, null);
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
这篇关于禁用Android WebView/WebViewClient启动的favicon.ico请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文