Download file from URL

Download image file from URL to ImageView Java Android source example code.

Context context = thisClass.this;
Drawable image = ImageOperations(context,
"http://android.okhelp.cz/images/adictionary/ad_4.png"
,"image.jpg");
ImageView imgView;
imgView = (ImageView)findViewById(R.id.idImageView);
imgView.setImageDrawable(image);
 
	private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
		try {
			InputStream is = (InputStream) this.fetch(url);
			Drawable d = Drawable.createFromStream(is, "src");
			return d;
		} catch (MalformedURLException e) {
			e.printStackTrace();
			return null;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
 
	public Object fetch(String address) throws MalformedURLException,IOException {
		URL url = new URL(address);
		Object content = url.getContent();
		return content;
	}
This entry was posted in Android Examples Code, Bitmap, drawing and tagged , , , , , , , , . Bookmark the permalink.


Comments are closed.



4,143 views