Skip to content

Instantly share code, notes, and snippets.

@princessdharmy
Created November 22, 2017 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save princessdharmy/de2c3e832fd8a773f0f18c3e0544a836 to your computer and use it in GitHub Desktop.
Save princessdharmy/de2c3e832fd8a773f0f18c3e0544a836 to your computer and use it in GitHub Desktop.
private class Content extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.show();
}
@Override
protected Void doInBackground(Void... voids) {
try {
//Connect to the website
Document document = Jsoup.connect(url).get();
//Get the logo source of the website
Element img = document.select("img").first();
// Locate the src attribute
String imgSrc = img.absUrl("src");
// Download image from URL
InputStream input = new java.net.URL(imgSrc).openStream();
// Decode Bitmap
bitmap = BitmapFactory.decodeStream(input);
//Get the title of the website
title = document.title();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
imageView.setImageBitmap(bitmap);
textView.setText(title);
progressDialog.dismiss();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment