Comments (1)
File dir = new File(getExternalCacheDir() + "/download/" + "public");
if (!dir.exists()) {
dir.mkdirs();
}
DownloadImpl.getInstance()
.with(getApplicationContext())
.target(new File(getExternalCacheDir() + "/download/" + "public" + "/" + "com.ss.android.article.news_636.apk"), this.getPackageName() + ".SampleFileProvider")//自定义路径需指定目录和authority(FileContentProvide),需要相对应匹配才能启动通知,和自动打开文件
.setUniquePath(false)//是否唯一路径
.setForceDownload(true)//不管网络类型
.setRetry(4)//下载异常,自动重试,最多重试4次
.setBlockMaxTime(60000L) //以8KB位单位,默认60s ,如果60s内无法从网络流中读满8KB数据,则抛出异常 。
.setConnectTimeOut(10000L)//连接10超时
.addHeader("xx", "cookie")//添加请求头
.setDownloadTimeOut(Long.MAX_VALUE)//下载最大时长
.setOpenBreakPointDownload(true)//打开断点续传
.setParallelDownload(true)//打开多线程下载
.autoOpenWithMD5("93d1695d87df5a0c0002058afc0361f1")//校验md5通过后自动打开该文件,校验失败会回调异常
// .autoOpenIgnoreMD5()
// .closeAutoOpen()
.quickProgress()//快速连续回调进度,默认1.2s回调一次
.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);
}
@MainThread //加上该注解,自动回调到主线程
@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) {
String md5 = Runtime.getInstance().md5(new File(path.getPath()));
Log.i(TAG, " path:" + path + " url:" + url + " length:" + new File(path.getPath()).length() + " md5:" + md5 + " extra.getFileMD5:" + extra.getFileMD5());
return super.onResult(throwable, path, url, extra);
}
});
自定义的目录需要提前创建。
from downloader.
Related Issues (20)
- ERROR: Failed to resolve: com.download.library:Downloader:4.1.5 HOT 1
- Google Play Suspended HOT 10
- 自动打开apk文件失败 HOT 1
- 关于分块传输 HOT 1
- 回调结果不在ui线程 HOT 1
- Targeting S+ 通知适配 FLAG_IMMUTABLE or FLAG_MUTABLE
- 关于Downloader发起请求时如何添加SSL证书? HOT 1
- DownloadNotifier.java line:110 com.download.library.DownloadNotifier.initBuilder HOT 3
- 5.0.3 Still have issue related to PendingIntent HOT 3
- 【BUG】当文件下载链接响应中包含文件长度,类型时,下载的文件是空白的,大小0byte HOT 1
- 5.0.3 还是有个PendingIntent的问题 HOT 1
- 为啥下载完成了状态栏通知进度一直卡100
- How to open downloaded files? HOT 1
- Android 13 support
- v5.0.4 not found on jitpack.io
- 200M的文件,下载几KB后就走到了onResult的回调里面,导致文件不完整
- 你这下载的文件被乱改名是几个意思啊。 HOT 1
- 下载会卡住
- file dir HOT 1
- need help HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from downloader.