WebView类,文件下载问题

时间:2019-05-21 10:35:09

标签: android 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)

0 个答案:

没有答案