Created
September 16, 2015 10:51
-
-
Save davidllorca/28bd2e368f37534f4c3f to your computer and use it in GitHub Desktop.
Download image with HttpURLConnection
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
/** | |
* Get image from url. | |
* | |
* @param src image url. | |
* @return Bitmap object. | |
*/ | |
private Bitmap getBitmapFromURL(String src) { | |
try { | |
URL url = new URL(src); | |
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | |
connection.setDoInput(true); | |
connection.connect(); | |
InputStream input = connection.getInputStream(); | |
Bitmap mBitmap = BitmapFactory.decodeStream(input); | |
return mBitmap; | |
} catch (IOException e) { | |
// Log exception | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment