首页 > 解决方案 > 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)

标签: androidandroid-webview

解决方案


推荐阅读