This is a very simple multi-task file downloader for android。
2 Files can be downloaded at breakpoints.(No additional use of sqlite to record download information)
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
dependencies { implementation 'com.github.jiangyingjun:OkDownloader:1.0.1' }
RealDownloadTask.Builder()
//File Network Address
.downloadUrl(url)
//Download file storage directory
.localPath(path)
//Custom Task ID
.setTag(tag)
//Task monitoring @param notifyInUI (true:Callback to main thread。false:Callback to task execution thread) #Task callback execution thread#
.listener(false,object :OnDownloadListener{
override fun onStart(task: DownloadTask) {
}
override fun onProcess(task: DownloadTask?, process: Long, total: Long) {
}
override fun onPause(task: DownloadTask) {
}
override fun onComplete(task: DownloadTask?) {
//Completed downloading files
task?.downloadFile()
}
override fun onError(task: DownloadTask?, error: Exception) {
}
})
.build()
//param isSerial #Is the download task serial。default :false(parallel downloading) #
OkDownloader.instance.start(true)
OkDownloader.instance.pause()
//In this queue. You can operate a specific task to start or pause
OkDownloader.instance.getRunnableList()
OkDownloader.instance.getRunnableList().forEach { innerRunnable ->
if (innerRunnable.taskId() == tag) {
Log.e("jyj-->", "operation task tag=${innerRunnable.taskTag()}")
//innerRunnable.taskStatus() #The status of the task#
if (innerRunnable.taskStatus() == DownloadTaskStatus.RUNNING) {
//Pause the task
innerRunnable.pause()
} else {
//Let the task begin
innerRunnable.start()
}
return@forEach
}
}
//Callback message interval (in milliseconds). Default: 50
OkDownloader.instance.setGlobalInterval(50)
//Number of task error retries. Default 3 times
OkDownloader.instance.setRetryTimes(3)
For more complete usage examples, please read demo