1

I have written a couple of live wallpapers in recent weeks using local resources. Now a potential client wants me to make one that loads and displays the photos (usually between 3 and 10) from his daily news report posted online. The report file has a URL along the lines of http://example.com/dailytext/report.html which loads images along the lines of http://example.com/dailymedia/obama.jpg The references in report.html look like
img src="../dailymedia/obama.jpg" ...

Am I supposed to use a WebView to do this? That doesn't seem quite right, because I don't want to display the HTML. I would think that I want to throw the raw HTML into an array, parse the HTML looking for the instances of "img src...", reconstruct the full URLs, then load the bitmaps. I'm getting the impression this is more of a pure Java task than anything to do with Android's specialized classes, but I don't know. Any suggestions about "best practice?"

2
  • 3
    I would find out first if there is a way to have the data provided from the server in a better format rather than having to scrape the html. If the server can provide a simple json list of images it would be a lot more efficient. Commented Apr 18, 2011 at 14:22
  • Point well taken. Though I accepted Richard's answer, I may well ask the client to put in a little effort to simplify my task. Thanks for your comment. Commented Apr 19, 2011 at 1:50

2 Answers 2

1

Unless I have misunderstood, this really isn't hard. You need to do the following:

  • Fetch the HTML, using either the native java networking api or something like HttpClient
  • Use a parser like Jericho or Dom4j to extract out the image links
  • Construct the absolute URLs, can be done with just java.net.URL
  • Fetch the images
Sign up to request clarification or add additional context in comments.

Comments

0

You could also prefer using Jsoup HTML Parser.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.