Skip to content

Instantly share code, notes, and snippets.

@taycaldwell
Last active August 29, 2015 14:11
Show Gist options
  • Save taycaldwell/e1f760a81db841030a81 to your computer and use it in GitHub Desktop.
Save taycaldwell/e1f760a81db841030a81 to your computer and use it in GitHub Desktop.
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