Rik*_*kin 5 java android webview kotlin
场景:
问题是,我正在做类似的事情来管理 Webview 下载:
webview.settings.javaScriptEnabled = true
webview.settings.domStorageEnabled = true
webview.setDownloadListener { url, userAgent, contentDisposition, mimeType, _ ->
val subpath = "/download" + "/" + "test" + ".pdf"
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val request = DownloadManager.Request(Uri.parse(formatUri(url)))
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
request.setAllowedOverRoaming(false)
request.setVisibleInDownloadsUi(true)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, subpath)
downloadManager.enqueue(request)
}
Run Code Online (Sandbox Code Playgroud)
但是,当然,这将不起作用,因为返回的url不是“正常”的 Uri,例如:
相反,它更像是这样:
Web 浏览器可以使用这种 url,但 webview 不能。
如何让 Android webview 将文件下载到设备?
| 归档时间: |
|
| 查看次数: |
668 次 |
| 最近记录: |