2

I am in the middle of creating an app, in that if user put a website url it will automatically convert to the website thumbnail. I made a http connection and got the html page as response. In that there is a meta tag that have the image/thumbnail.

<meta property="og:image" itemprop="image primaryImageOfPage" content="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded" />

So my question is how to extract that image.

I tried Jsoup , I cant extract the image from that.

Geeks please help me

noobEinstien
  • 3,147
  • 4
  • 24
  • 42

1 Answers1

6

Use jsoup for extracting website thumbnail from HTML meta tag

Document doc=Jsoup.connect(WEBSITE_URL).get();
Elements elements=doc.select("meta");

for(Element e: elements){
  //fetch image url from content attribute of meta tag. 
  imageUrl = e.attr("content");

  //OR more specifically you can check meta property.
  if(e.attr("property").equalsIgnoreCase("og:image")){
     imageUrl = e.attr("content");
     break;
  } 
}

Now use Glide An image loading and caching library for Android.

Glide.with(this).load(imageUrl).into(imageView);
Satendra
  • 6,755
  • 4
  • 26
  • 46
  • +1 for answer...but this solution will cause issue on main thread ..so use Handler, to post to the UI Thread: link:- https://stackoverflow.com/questions/12716850/android-update-textview-in-thread-and-runnable – Wini Oct 14 '21 at 12:30