【发布时间】:2018-10-29 15:54:29
【问题描述】:
以下代码可以完美地下载外部存储中的 mp3 文件,但不能下载内部存储中的文件。许多智能手机没有外部存储。我能做些什么?如果需要的话,我不知道如何在 kotlin 中实现异步任务。
mywebView.setDownloadListener(object : DownloadListener {
override fun onDownloadStart(url: String, userAgent: String,
contentDisposition: String, mimetype: String,
contentLength: Long) {
val request = DownloadManager.Request(Uri.parse(url))
request.allowScanningByMediaScanner()
request.setDescription("Download file...")
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype))
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) //Notify client once download is completed!
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, mimetype )
val webview = getSystemService(DOWNLOAD_SERVICE) as DownloadManager
webview.enqueue(request)
Toast.makeText(getApplicationContext(), "Download avviato", Toast.LENGTH_LONG).show()
}
})
【问题讨论】: