I'm trying to get a png Bitmap from URL but the Bitmap is always NULL in with this code:
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
Activity activity;
public DownloadImageTask(ImageView bmImage, Activity activity) {
this.bmImage = bmImage;
this.activity = activity;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Log.i("LEGGERE", urldisplay);
Bitmap mIcon11 = null;
try {
URL url = new URL(urldisplay);
mIcon11 = BitmapFactory.decodeStream(url.openConnection().getInputStream());
if (null != mIcon11)
Log.i("BITMAP", "ISONOTNULL");
else
Log.i("BITMAP", "ISNULL");
} catch (Exception e) {
Log.e("Error", "PORCA VACCA");
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
And I create a DownloadImageTask in onCreate():
new DownloadImageTask((ImageView) findViewById(R.id.provaaa),this)
.execute("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png");
Do I make some mistakes?