简体   繁体   中英

Display the Android WebView's 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 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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM