Guest User

Untitled

a guest
Nov 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. private class Content extends AsyncTask<Void, Void, Void> {
  2.  
  3. @Override
  4. protected void onPreExecute() {
  5. super.onPreExecute();
  6. progressDialog = new ProgressDialog(MainActivity.this);
  7. progressDialog.show();
  8. }
  9.  
  10. @Override
  11. protected Void doInBackground(Void... voids) {
  12. try {
  13. //Connect to the website
  14. Document document = Jsoup.connect(url).get();
  15.  
  16. //Get the logo source of the website
  17. Element img = document.select("img").first();
  18. // Locate the src attribute
  19. String imgSrc = img.absUrl("src");
  20. // Download image from URL
  21. InputStream input = new java.net.URL(imgSrc).openStream();
  22. // Decode Bitmap
  23. bitmap = BitmapFactory.decodeStream(input);
  24.  
  25. //Get the title of the website
  26. title = document.title();
  27.  
  28. } catch (IOException e) {
  29. e.printStackTrace();
  30. }
  31. return null;
  32. }
  33.  
  34. @Override
  35. protected void onPostExecute(Void aVoid) {
  36. super.onPostExecute(aVoid);
  37.  
  38. imageView.setImageBitmap(bitmap);
  39. textView.setText(title);
  40. progressDialog.dismiss();
  41. }
  42. }
Add Comment
Please, Sign In to add comment