Android WebView Icon Display

I want to display the icon of the website I am accessing via android.webkit.WebView. I tried two ways to get it:

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

2) The WebChromeClient.onReceivedIcon() method is never called.

3) WebView.getFavicon() is onPageStarted() in onPageStarted() and onPageFinished() , but always returns null.

I was unable to find an online example that shows how to access the icon. Any hints would be greatly appreciated.

+6
android favicon
source share
2 answers

In order for WebView methods and listeners to be displayed, you must first open WebIconDatabase manually. Usually you 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 do this, you should start receiving onReceivedIcon() callbacks for any WebView in this Activity, and the getFavicon() method should also start returning a valid object, not null, when icons are available.

+18
source share

I think there is a getFavicon() method for the getFavicon() . here is my stupid question, have you tried this?

0
source share

All Articles