【问题标题】:Download Manager notification not showing when downloading a file下载文件时未显示下载管理器通知
【发布时间】:2021-07-18 16:51:23
【问题描述】:

我有一个应用程序,其中我具有下载已存储在 firebase 中的文件的功能。我已经实现了使用下载管理器下载的代码,同时向用户显示下载该文件的通知,但由于某种原因它无法正常工作。

这是我的代码

val downloadRequest = DownloadManager.Request(Uri.parse(model.document.substringBeforeLast(".")))
downloadRequest.setTitle("الملف")
downloadRequest.setDescription("تحميل الملف")
downloadRequest.setVisibleInDownloadsUi(true)
downloadRequest.setDestinationUri(uri.toUri())
downloadRequest.allowScanningByMediaScanner()
downloadRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
downloadManager.enqueue(downloadRequest)

【问题讨论】:

    标签: android kotlin notifications


    【解决方案1】:

    文件是否已下载但通知不可见或文件也未下载?

    试试这个,如果它仍然不起作用,请告诉我:)

    downloadRequest.setNotificationVisibility(
    DownloadManager.Request.VISIBILITY_VISIBLE
    )
    

    编辑

    我上次使用它时,您指定的目的地似乎有所不同。

    val directory: File = File(Environment.getExternalStorageDirectory().path + "/myFile")
    
        if(!directory.exists()) {
            directory.mkdir()
        }
    
    ...
    
    downloadRequest.setDestinationInExternalPublicDir("/myFile","android")
    

    【讨论】:

    • 我会验证你的答案并让你知道
    • 我可以存储文件,但问题仍然是下载文件时没有显示的通知
    • 你在Google Pixel这样的模拟器上试过了吗?这可能是您的OS 阻止notifications 的问题,就像某些设备在battery saving 模式下所做的那样?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    • 1970-01-01
    • 1970-01-01
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多