OkDownload 进行下载
fun downloadPic(userId: String?, url: String, parentFile: File) {
val task: DownloadTask = DownloadTask.Builder(url, parentFile)
.setFilename(userId) // the minimal interval millisecond for callback progress
.setMinIntervalMillisCallbackProcess(30) // do re-download even if the task has already been completed in the past.
.setPassIfAlreadyCompleted(false)
.build()
// execute task synchronized
task.execute(object : DownloadListener2() {
override fun taskStart(task: DownloadTask) {
LogUtils.v("FaceManager", "开始下载")
}
override fun taskEnd(task: DownloadTask, cause: EndCause, realCause: Exception?) {
LogUtils.v("FaceManager", "下载结束" + task.file?.path ?: "")
}
})
}
Okgo 下载
public void downloadFile(String url, String fileName) {
OkGo.<File>get(url)
.tag(this)
.execute(new FileCallback("文件路径", fileName) {
@Override
public void onStart(Request<File, ? extends Request> request) {
super.onStart(request);
}
@Override
public void onSuccess(Response<File> response) {
}
@Override
public void onError(Response<File> response) {
super.onError(response);
}
});
}
网友评论