Display the Android WebView's favicon

前端 未结 2 456
轮回少年
轮回少年 2021-02-06 09:24

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()

相关标签:
2条回答
  • 2021-02-06 10:02

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

    0 讨论(0)
  • 2021-02-06 10:09

    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.

    0 讨论(0)
提交回复
热议问题