Display the Android WebView's favicon

半城伤御伤魂 提交于 2019-12-03 13:11:59

问题


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 is never called.

3) Called WebView.getFavicon() in onPageStarted() and onPageFinished() but it always returns null.

I haven't been able to find an example online that shows how to access the favicon. Any hints would be greatly appreciated.


回答1:


For the WebView icon methods and listeners to work, you need to first open the WebIconDatabase manually. You would typically do this in the onCreate() method of your Activity.

Try adding the following line to onCreate():

WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());

Once you've done this, you should start getting onReceivedIcon() callbacks for any WebView in this Activity, and the getFavicon() method should also start returning a valid object rather than null whenever icons are available.




回答2:


I think to remember that there is a method getFavicon() available for the WebView object. here is my stupid question did you try that?



来源:https://stackoverflow.com/questions/3462582/display-the-android-webviews-favicon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!