Home

Awesome

Downloader

Downloader 是一个非常轻巧以及功能强大快速下载库,只有50KB 左右大小,对于大多数应用来说,性价比最高的一个下载库, Downloader 提供的API更简单、轻量且Downloader提供同步下载,系统通知进度等功能。

预览图

<a href="img/download1.jpg"><img src="img/download1.jpg" width="48%"/></a> <a href="img/download2.jpg"><img src="img/download2.jpg" width="48%"/></a>

特性

下载

allprojects {
	repositories {
			...
			maven { url 'https://jitpack.io' }
	}
}

例子

同步

File file = DownloadImpl.getInstance(getApplicationContext())
				.url("http://shouji.360tpcdn.com/170918/93d1695d87df5a0c0002058afc0361f1/com.ss.android.article.news_636.apk")
				.get();

异步

DownloadImpl.getInstance(getApplicationContext())
                .url("http://shouji.360tpcdn.com/170918/f7aa8587561e4031553316ada312ab38/com.tencent.qqlive_13049.apk")
                .enqueue();

进度监听

DownloadImpl.getInstance(getApplicationContext())
		.target(new File(this.getExternalCacheDir(), "com.ss.android.article.news_636.apk"))
		.setUniquePath(false)
		.setForceDownload(true)
.url("http://shouji.360tpcdn.com/170918/93d1695d87df5a0c0002058afc0361f1/com.ss.android.article.news_636.apk")
		.enqueue(new DownloadListenerAdapter() {
					@Override
					public void onStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength, Extra extra) {
						super.onStart(url, userAgent, contentDisposition, mimetype, contentLength, extra);
					}

					@Override
					public void onProgress(String url, long downloaded, long length, long usedTime) {
						super.onProgress(url, downloaded, length, usedTime);
						Log.i(TAG, " progress:" + downloaded + " url:" + url);
					}

					@Override
					public boolean onResult(Throwable throwable, Uri path, String url, Extra extra) {
						Log.i(TAG, " path:" + path + " url:" + url + " length:" + new File(path.getPath()).length());
						return super.onResult(throwable, path, url, extra);
					}
		});

默认的文件目录

/data/data/com.download.sample(packagename)/cache/download/private/filename.jpg
/data/data/com.download.sample(packagename)/cache/download/public/filename.jpg