android - android DownloadManager 通知不可见
问题描述
我正在尝试使用 下载文件DownloadManager
,下载开始但未查看通知。仅在 android API 27 上尝试过
val url="http://exmaple.com/mp4.mp4" //a fabricated url
val request = DownloadManager.Request(Uri.parse(url))
.setTitle("Dummy File")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
.setAllowedOverMetered(true)
.setVisibleInDownloadsUi(true)
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
downloadManager.enqueue(request)
解决方案
问题不在于您的代码,我在尝试时发现了这一点。这是因为您尝试下载的示例 URL 是不允许的。
W/DownloadManager: [151] Stop requested with status BAD_REQUEST: Cleartext traffic not permitted for UID 10202: http://exmaple.com/...
尝试“ https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4 ”示例视频,它工作正常。
快乐的编码......)
推荐阅读
- vue.js - 如何通过 VueJS 中的操作访问商店?
- inno-setup - Inno 下载插件 - 可调整大小?
- bash - 通过调用父文件夹名称运行脚本
- apache-spark - 为什么 Spark Structured Streaming 作业中缺少来自 StreamingQueryListener 的 QueryProgressEvent 日志?
- node.js - 如何使我的 node.js 应用程序可公开访问?
- javascript - 为什么在这个 javascript 代码段提升问题上打印 10
- java - 为什么“not”运算符不起作用(布尔值)?
- javascript - 针对数据库验证数据列表,然后阻止表单提交
- ms-access - 如何在 MS Access 中使用 Dlookup 控制的文本框中输入值
- python - iloc 条件分组由 pandas 填充