Archivi tag: DownloadImageTask

come scaricare (download) una immagine da web (url) usando AsyncTask in Android

asynctask steps
asynctask steps
LA CHIAMATA
new DownloadImageTask(holder.imageview).execute(urlImgS);


LA ASYNCTASK
		
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
		ImageView bmImage;

public DownloadImageTask(ImageView bmImage) {
	this.bmImage = bmImage;
}

protected Bitmap doInBackground(String... urls) {
	String urldisplay = urls[0];
	Bitmap mIcon11 = null;
	try {
	   InputStream in = new  java.net.URL(urldisplay).openStream();
	mIcon11 = BitmapFactory.decodeStream(in);
	} catch (Exception e) {
	  Log.e("Error", e.getMessage());
	  e.printStackTrace();
	}
	 return mIcon11;
}

protected void onPostExecute(Bitmap result) {
   bmImage.setImageBitmap(result);
}
}
}//AsyncTask
Annunci