Android 将文件从webview下载到内部存储器
下面的代码可以完美地将mp3文件下载到外部存储器中,但无法将文件下载到内部存储器中。很多智能手机都没有外部存储器。我能做什么?如果需要的话,我不知道如何在kotlin中实现异步任务Android 将文件从webview下载到内部存储器,android,kotlin,Android,Kotlin,下面的代码可以完美地将mp3文件下载到外部存储器中,但无法将文件下载到内部存储器中。很多智能手机都没有外部存储器。我能做什么?如果需要的话,我不知道如何在kotlin中实现异步任务 mywebView.setDownloadListener(object : DownloadListener { override fun onDownloadStart(url: String, userAgent: String,
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()
}
})
目前无法测试代码,但应该如下所示:
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.getExternalStorageDirectory(), mimetype )
val webview = getSystemService(DOWNLOAD_SERVICE) as DownloadManager
webview.enqueue(request)
Toast.makeText(getApplicationContext(), "Download avviato", Toast.LENGTH_LONG).show()
}
})
读和读。因此,所有智能手机都有外部存储,而不是所有智能手机都有SD卡。他要求的是内部存储,而不是外部存储