的Android的WebView getFavicon()返回null [英] Android WebView getFavicon() returning null
问题描述
我试图用后得到加载页面的图标
I'm trying to get the favicon of the loaded page after using
WebView webView = new WebView(getActivity());
webView.loadUrl("http://" + url);
我附加异步 WebViewClient
到的WebView
来获得图标加载后
webView.setWebViewClient(new WebViewClient()
{
@Override
public void onPageFinished(WebView view, String url)
{
String linkTitle = view.getTitle();
Bitmap favicon = view.getFavicon();
onLinkUrlFinished(url, linkTitle);
}
});
该图标找回总是空,即使是网站,如谷歌/ Facebook的有网站图示是肯定的。
The favicon getting back is always null, even for websites such as google/facebook that has favicons for sure.
另一个线程说,使用 WebIconDatabase
,但它去precated:
<一href=\"http://stackoverflow.com/questions/3462582/display-the-android-webviews-favicon/5346347#5346347\">Display在Android的WebView图标
Another thread says to use WebIconDatabase
but it's deprecated:
Display the Android WebView's favicon
在Android网站上的API是指 WebViewClient.onReceivedIcon
甚至犯规存在。的http://developer.android.com/reference/android/webkit/WebView.html#getFavicon%28%29
The API on android site refers to WebViewClient.onReceivedIcon
which doesnt even exist.http://developer.android.com/reference/android/webkit/WebView.html#getFavicon%28%29
这是怎么回事?
推荐答案
所以在最后我最终没有使用德precated API,而不是我发现,如果你把 /favicon.ico
域后,它会给你的 ICO
文件,我到底用来获取图像。这个URI API将有一个和getHost()
方法,它会给你的主机,而不必手动解析它
So in the end I didn't end up using the deprecated API, instead I found out that if you put /favicon.ico
after the domain, it'll give you the ico
file, which I used in the end to fetch the image. The Uri API will have a getHost()
method that will give you the host without having to manually parse it
String faviconUrl = Uri.parse(url).getHost() + "/favicon.ico";
有关谷歌为例图标URL将被www.google.com/favicon.ico
For google for example the icon url will be www.google.com/favicon.ico
这篇关于的Android的WebView getFavicon()返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!