android中webview接收favicon总是获取为null解决方案

在Android WebView中,默认情况下,通过WebChromeClient的onReceivedIcon方法和webview.getFavicon()都无法获取到网站的favicon.ico。为了解决这个问题,需要在Activity的onCreate()方法中手动打开WebIconDatabase。例如:WebIconDatabase.getInstance().open(Util.getDirs(getCacheDir().getAbsolutePath()+"/icons/"))。确保图标目录已创建,否则会报错。这样,WebChromeClient的回调和webview.getFavicon()就能返回正确的favicon了。
摘要由CSDN通过智能技术生成

在webview中,我们需要获取网站的favicon.ico图标,但是默认状态下,WebChromeClient中的onReceivedIcon方法获取到的icon总是为null;

webview.getFavicon();获得到的还是null,这个就奇怪了,于是

经过一番google,发现老外也遇到了这个问题.

=======================================================

http://stackoverflow.com/questions/3462582/display-the-android-webviews-favicon

I'd like to display the favicon of the website I am accessing via the android.webkit.WebView. I've tried two ways to get it:

1) WebViewClient.onPageStarted() method has a favicon parameter that is always null.

2) WebChromeClient.onReceivedIcon() method

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值