Rau*_*rma 6 java android android-webview kotlin android-download-manager
这是当我从 android 中的 webView 下载任何内容时我尝试执行相同操作的代码。
webview.setDownloadListener { url, userAgent, contentDisposition, mimetype, l ->
val request = DownloadManager.Request(Uri.parse(url))
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype))
request.setDescription("Downloading file...")
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
var newuri=FileProvider.getUriForFile(context, "com.shyptsolution.classproject"+ ".provider", File(context.filesDir,"fileName"))
// request.setDestinationUri(newuri)
request.setDestinationInExternalPublicDir(
context.filesDir.absolutePath,
URLUtil.guessFileName(url, contentDisposition, mimetype)
)
val dm =context.applicationContext.getSystemService(DOWNLOAD_SERVICE) as DownloadManager
dm!!.enqueue(request)
}
Run Code Online (Sandbox Code Playgroud)
但我收到错误,它不是标准目录。如何将文件保存在缓存或文件目录中?
我只想查看files下图所示文件夹中的文件。
| 归档时间: |
|
| 查看次数: |
3684 次 |
| 最近记录: |