Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. public class Connection {
  2.  
  3. ArrayList<String> StringArray = new ArrayList<String>();
  4. private String fileExtension = "jpg";
  5. private String html = "http://mcs.une.edu.au/~salmutai/cameras";
  6. private int count = 0;
  7.  
  8.  
  9. public void UrlExtract() throws Exception {
  10.  
  11. Document doc = Jsoup.connect(html).get();
  12. Elements castURL = doc.select("a");
  13. for (Element el : castURL) {
  14. String src = el.absUrl("href");
  15. String extension = src.substring(src.lastIndexOf(".") + 1,
  16. src.length());
  17. if (extension.equalsIgnoreCase(fileExtension)) {
  18. StringArray.add(src);
  19. count++;
  20.  
  21. }
  22. }
  23.  
  24. }
  25.  
  26. public int getCount() throws Exception {
  27. return count;
  28. }
  29.  
  30. public String ImgArray(int i) throws Exception {
  31.  
  32. String[] StrArray = new String[count];
  33. StrArray = (String[]) StringArray.toArray(StrArray);
  34. return StrArray[i];
  35. }
  36.  
  37. String text = "Found " + StringArray.size() + " images at the url: " + html;
  38. Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
  39.  
  40. try {
  41. Connection co = new Connection();
  42. co.UrlExtract();
  43. } catch (Exception e) {
  44. // TODO Auto-generated catch block
  45. e.printStackTrace();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement