我想展示我通过android.webkit.WebView访问该网站的图标。我试过两种方式来获得它:
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()
方法有一个图标参数总是空。
1) WebViewClient.onPageStarted()
method has a favicon parameter that is always null.
2) WebChromeClient.onReceivedIcon()
方法不会被调用。
2) WebChromeClient.onReceivedIcon()
method is never called.
3)名为 WebView.getFavicon()
在 onPageStarted()
和 onPageFinished( )
但它总是返回null。
3) Called WebView.getFavicon()
in onPageStarted()
and onPageFinished()
but it always returns null.
我一直没能找到一个例子网上展示了如何访问图标。任何提示将大大AP preciated。
I haven't been able to find an example online that shows how to access the favicon. Any hints would be greatly appreciated.
有关web视图图标的方法和听众的工作,你需要先手动打开WebIconDatabase。你通常会在你活动的的onCreate()
办法做到这一点。
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.
尝试添加以下行的onCreate()
:
WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
一旦你做到了这一点,你应该开始让 onReceivedIcon()
回调,本次活动的任何web视图,而 getFavicon()
方法也开始返回一个有效的对象,而不是空时的图标是可用的。
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.