优化
This commit is contained in:
@@ -83,18 +83,25 @@ class DownloadService : BaseService() {
|
|||||||
toastOnUi("已在下载列表")
|
toastOnUi("已在下载列表")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 指定下载地址
|
kotlin.runCatching {
|
||||||
val request = DownloadManager.Request(Uri.parse(url))
|
// 指定下载地址
|
||||||
// 设置通知
|
val request = DownloadManager.Request(Uri.parse(url))
|
||||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN)
|
// 设置通知
|
||||||
// 设置下载文件保存的路径和文件名
|
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN)
|
||||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
|
// 设置下载文件保存的路径和文件名
|
||||||
// 添加一个下载任务
|
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
|
||||||
val downloadId = downloadManager.enqueue(request)
|
// 添加一个下载任务
|
||||||
downloads[downloadId] = Pair(url, fileName)
|
val downloadId = downloadManager.enqueue(request)
|
||||||
queryState()
|
downloads[downloadId] = Pair(url, fileName)
|
||||||
if (upStateJob == null) {
|
queryState()
|
||||||
checkDownloadState()
|
if (upStateJob == null) {
|
||||||
|
checkDownloadState()
|
||||||
|
}
|
||||||
|
}.onFailure {
|
||||||
|
when (it) {
|
||||||
|
is SecurityException -> toastOnUi("下载出错,没有存储权限")
|
||||||
|
else -> toastOnUi("下载出错,${it.localizedMessage}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user