Created
November 22, 2017 03:29
-
-
Save princessdharmy/de2c3e832fd8a773f0f18c3e0544a836 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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