I'm trying to load an image from URL into Bitmap object, but I always end up with NetworkInUIThread kind of exception. Can anyone provide me a library for this?
Note, that I'm not trying to put the image into ImageView, I want to put it into Bitmap object first, as it will be used more times later in my app.
I found this code in some other StackOverflow thread, but it doesn't work.
public static 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 myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
}catch(IOException e){
return null;
}
}