Last active
August 29, 2015 14:11
-
-
Save taycaldwell/e1f760a81db841030a81 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
import android.graphics.Bitmap; | |
import android.graphics.BitmapFactory; | |
import android.os.AsyncTask; | |
import android.util.Log; | |
import android.widget.ImageView; | |
import java.io.InputStream; | |
public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { | |
ImageView image; | |
public DownloadImageTask(ImageView bitmap) { | |
this.image = bitmap; | |
} | |
protected Bitmap doInBackground(String... urls) { | |
String url = urls[0]; | |
Bitmap icon = null; | |
try { | |
InputStream in = new java.net.URL(url).openStream(); | |
icon = BitmapFactory.decodeStream(in); | |
} catch (Exception e) { | |
Log.e("Error", e.getMessage()); | |
e.printStackTrace(); | |
} | |
return icon; | |
} | |
protected void onPostExecute(Bitmap result) { | |
image.setImageBitmap(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment