Get 32px favicon.ico

浪尽此生 提交于 2019-12-12 22:31:46

问题


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


回答1:


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.




回答2:


Smart phone can't effect that.Actually on some website favicon size 16px and other have 32px. Like facebook,google,twitter have 16px favicon And yahoo,google plus have 32 px favicon...



来源:https://stackoverflow.com/questions/15097092/get-32px-favicon-ico

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!