From 2f37a615f5d836cc726c4f0b9a2bb41365786ea4 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 7 Sep 2020 22:00:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E9=98=85=E7=95=8C=E9=9D=A2=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/rss/read/ReadRssActivity.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 99728cc3c..3e48c3ebf 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -1,10 +1,13 @@ package io.legado.app.ui.rss.read import android.annotation.SuppressLint +import android.app.DownloadManager import android.content.Intent import android.content.pm.ActivityInfo import android.content.res.Configuration +import android.net.Uri import android.os.Bundle +import android.os.Environment import android.view.* import android.webkit.* import androidx.core.view.size @@ -138,6 +141,33 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } return@setOnLongClickListener false } + web_view.setDownloadListener { url, _, contentDisposition, _, _ -> + val fileName = URLUtil.guessFileName(url, contentDisposition, null) + ll_view.longSnackbar(fileName, getString(R.string.action_download)) { + // 指定下载地址 + val request = DownloadManager.Request(Uri.parse(url)) + // 允许媒体扫描,根据下载的文件类型被加入相册、音乐等媒体库 + @Suppress("DEPRECATION") + request.allowScanningByMediaScanner() + // 设置通知的显示类型,下载进行时和完成后显示通知 + request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) + // 允许在计费流量下下载 + request.setAllowedOverMetered(false) + // 允许该记录在下载管理界面可见 + @Suppress("DEPRECATION") + request.setVisibleInDownloadsUi(false) + // 允许漫游时下载 + request.setAllowedOverRoaming(true) + // 允许下载的网路类型 + request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI) + // 设置下载文件保存的路径和文件名 + request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName) + val downloadManager = getSystemService(DOWNLOAD_SERVICE) as DownloadManager + // 添加一个下载任务 + val downloadId = downloadManager.enqueue(request) + print(downloadId) + } + } } private fun saveImage() {