GithubHelp home page GithubHelp logo

irmobydick / android-file-download Goto Github PK

View Code? Open in Web Editor NEW

This project forked from logistic-infotech/android-file-download

0.0 1.0 0.0 2.23 MB

this demo is created to download file with support of LoopJ Lib

android-file-download's Introduction

Android-File-Download

Android download file with progressbar 0 to 100

There is very less code we need to put to download file just like below:

public void fileDownload(String url) {
		URL = url;
		
		fileName = url.substring(url.lastIndexOf('/') + 1, url.length());

		File f = LiApplication.getFilePath(fileName, MainActivity.this);
		// if (f.exists()) {
		System.out.println("getting image from folder " + f);
		// myBitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
		// imageView.setImageBitmap(myBitmap);

		// } else {
		System.out.println("getting image from url" + f);
		progressBar.setProgress(0);
		progressBar.setVisibility(View.VISIBLE);
		LIRestClient.downloadFile(url, null, new FileAsyncHttpResponseHandler(f) {

			@Override
			public void onSuccess(int statusCode, File file) {
				Log.i(TAG, "onClick onSuccess :" + statusCode);

				Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
				imageView.setImageBitmap(myBitmap);

				// progressBar.setVisibility(View.GONE);
			}

			@Override
			public void onProgress(int bytesWritten, int totalSize) {
				int totProgress = (int) (((float) bytesWritten * 100) / totalSize);
				Log.i("Progress::::", "" + totProgress);
				if (totProgress > 0) {
					progressBar.setProgress(totProgress);
				}
			}

			@Override
			public void onFailure(int statusCode, Header[] headers, Throwable e, File response) {
				response.delete();
				Log.i(TAG, "onClick onFailure :" + statusCode + " " + e.getLocalizedMessage());
				e.printStackTrace();
				// progressBar.setVisibility(View.GONE);

				int resID = getResources().getIdentifier(strDefaultImage, "drawable", c.getPackageName());
				imageView.setImageResource(resID);
			}
		});
		// }
	}

android-file-download's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.