The WebView
component has a gevFavicon()
method so it's definitely possible to decode ICO files in Android. You could have a look at the Android source to see how ICO files are parsed. I've had a quick look but can't find the relevant part.
Alternatively, you should be use the SDK to get favicons for you. However, I've had a quick try and can't get it to work.
For what it's worth here's my test code, noting again that this doesn't work:
String url = "http://stackoverflow.com";
WebView wv = new WebView(this);
wv.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
Log.i("HelloAndroid","Loaded " + url);
Log.i("HelloAndroid","Icon " + (view.getFavicon() == null ? "not" : "") + " found");
}
});
WebIconDatabase wid = WebIconDatabase.getInstance();
wid.requestIconForPageUrl(url, new WebIconDatabase.IconListener() {
public void onReceivedIcon(String url, Bitmap icon) {
Log.i("HelloAndroid","Found Icon for " + url);
}
});
wv.loadUrl("http://stackoverflow.com");
Log.i("HelloAndroid","Loading " + url);
The problem may be down to the fact that I'm not adding the WebView
to a visible View
. If you do get this to work I'd be interested to hear what you did.
So sorry for giving two half complete answers, but I thought it was worth posting what I found.