android - WebView 类,文件下载问题
问题描述
我无法使用 HTTPS(https://) 传输协议下载文件。文件在使用 Http(http://) 时下载
val request = DownloadManager.Request(
Uri.parse(url))
val dm = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val fileName = URLUtil.guessFileName(url, contentDisposition, mimetype)
val destinationFile = File(
Environment.getExternalStorageDirectory().absolutePath + "/FileName",
fileName)
request.allowScanningByMediaScanner()
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
request.addRequestHeader("User-Agent", userAgent)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setDestinationUri(Uri.fromFile(destinationFile))
dm.enqueue(request)
解决方案
推荐阅读
- go - `io.Copy` 文件大小与原始文件不同
- mysql - 如果 AND 语句没有产生结果,我如何返回空值?
- reactjs - React 内联函数性能说明
- three.js - Three.js - 平滑的阴影导致奇怪的边缘
- java - 如何动态使用java在spark数据框中展平复杂的嵌套json
- nlog - 布局渲染可以用于文件名吗?
- go - 如何使文件阅读器功能更有效?
- user-defined-functions - 如何在 Select 查询中调用 Snowflake UDF
- javascript - 如何在 react-admin 中的嵌套 ArrayInput / FormDataConsumer 中调用 getSource
- hive - Hive 创建带有 SERDEPROPERTIES 的表抛出错误