mask mask - 5 months ago 125
Android Question

Any way to grab a logo icon from website URL, programmatically?

I am in the process of creating an activity where I will show the list of website visited with its logo and its alias name chosen by user.

e.g.


  • Recent Websites Visited

    logo1 website1/alias name

    logo2 website2/alias name

    .

    . so no



The question is, (Ref. attached image) How to get website logo displayed on left side of http://?

Like below I want to just grab the icon and save it locally

Answer

It's called a favicon, and all you have to do is:

  1. If there's an icon at /favicon.ico, use that.
  2. Otherwise, get the content of the page, and extract the location from <link rel="shortcut icon" href="URL goes here" />. You’ll need to use an HTML parser and find the <link> with a rel of either icon or shortcut icon.