Im trying to get the 32px favicon.ico of the websites, but the response it obtain is the 16px favicon, I guess because I´m trying to obtain it by the smarthphone, but I try to change the user agent of the http petition with no result here is my code:
DefaultHttpClient client = new DefaultHttpClient();
String baseUrl = getBaseUrl(url);
HttpGet httpGet = new HttpGet(baseUrl + "/favicon.ico");
httpGet.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19");
HttpResponse httpResponse = null;
try {
httpResponse = client.execute(httpGet);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}catch (NullPointerException e) {
e.printStackTrace();
}
InputStream is = null;
try {
is = (java.io.InputStream) httpResponse.getEntity().getContent();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
Drawable favicon = Drawable.createFromStream(is, "src");
final BitmapDrawable bd = (BitmapDrawable) favicon;
Any idea how to get it? Thanks
A .ico
file can contain several pictures. Therefore, the favicon.ico
file you get may well contain a 16x16 picture and a 32x32 picture.
You can use the icotool
command line tool to analyze a .ico
file:
# On Ubuntu
sudo apt-get install icoutils
icotool -l favicon.ico
--icon --index=1 --width=16 --height=16 --bit-depth=32 --palette-size=0
--icon --index=2 --width=32 --height=32 --bit-depth=32 --palette-size=0
--icon --index=3 --width=48 --height=48 --bit-depth=32 --palette-size=0
# 3 pictures in this favicon.ico file
On Windows, when you open a .ico
file with the default viewer (just double-click the file), the viewer let you navigate through the multiple pictures contained in the file. It does not print their resolution, but at least you have a clue about what is going on with your strange behavior.