a multi-thread downloader for okhttp!
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.li-xiaojun:OkhttpDownloader:latest release'
}
- multi-thread download
- support break-download
- db save downloadInfo
-
下载方法:
//需要自己维护任务id DownloadEngine.create(this).download(taskId, url, path);
-
暂停方法:
DownloadEngine.create(this).pause(taskId);
-
设置最大同时运行的任务数量:
DownloadEngine.create(this).setMaxTaskCount(5);
-
添加和移除下载监听器:
//添加 DownloadEngine.create(this).addDownloadObserver(new DownloadEngine.DownloadObserver() { @Override public void onDownloadUpdate(DownloadInfo downloadInfo) { } },taskId...); //移除 DownloadEngine.create(this).removeDownloadObserver(this);
-
获取下载详细数据:
DownloadEngine.create(this).getDownloadInfo(taskId);
-
删除下载数据,同时删除数据库记录和本地文件:
DownloadEngine.create(this).deleteDownloadInfo(downloadInfo);