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

标签: androidandroid-download-manager

解决方案


问题不在于您的代码,我在尝试时发现了这一点。这是因为您尝试下载的示例 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 ”示例视频,它工作正常。

快乐的编码......)


推荐阅读