- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用下载管理器
从我的服务器下载图像。
它可以很好地下载文件并将其放在我想要的位置。但出于某种原因,通知一直存在,我似乎无法删除它。下载管理器的代码如下:
mDownloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
Uri uri = Uri.parse("URL"));
long enqueue = mDownloadManager.enqueue(new DownloadManager.Request(uri)
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
.setAllowedOverRoaming(false)
.setTitle("Title")
.setDescription("File description")
.setDestinationInExternalPublicDir("Folder", "Filename")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE));
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
Toast.makeText(getApplicationContext(), "Download Completed", Toast.LENGTH_SHORT).show();
}
};
下载通知后如何删除通知?。
我已经尝试设置所有不同的通知可见性模式,但没有成功。 BroadcastReceiver 完成后我可以做些什么吗?
最佳答案
我设法解决了我的问题。在 BroadcastReceiver
中,我必须从 Intent 中获取下载 ID,并将其从 DownloadManager
中删除。
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
Toast.makeText(getApplicationContext(), "Download Completed", Toast.LENGTH_SHORT).show();
// Get the download_id of the completed download.
long download_id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
// Remove the completed download from the DownloadManager
mDownloadManager.remove(download_id);
}
};
我还想指出,通过执行 mDownloadManager.remove(download_id)
,这将从内存中删除文件。我必须添加额外的代码才能将文件永久保存在我最初想要保存的位置。
关于Android:DownloadManager - 通知粘贴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14443536/
我有一个使用 DownloadManager 下载多个文件的应用程序.在 SD 卡上安装应用程序会导致广播接收器接收到带有 DownloadManager.ERROR_FILE_ERROR 的 Int
我遇到了 DownloadManager 的奇怪问题, 下载成功但文件未存储。 所以这是我的代码: try { DownloadManager manager = (DownloadManag
我的下载管理器未在状态栏中显示通知图标。当您打开所有通知时,通知是他们的,但状态栏中没有图标,因此人们无法一眼看出下载已经开始。这在旧设备上不是问题,并且仅在运行 android 9 pie 的 an
有人提出了一些类似的问题,但我的有点不同,我有以下代码在我的应用程序上进行下载: DownloadManager.Request request = new DownloadManager.Requ
我想从我的服务器下载 *.apk 文件,服务器上的文件类型是 *.apk 并且 MIME 是 application/vnd.android.package-archive",当使用 Download
我需要中止所有失败/暂停/挂起/正在运行的下载,但保留成功的下载。我认为这是通过 DownloadManager 查询完成的,但我不知道如何编写代码。请帮忙。 最佳答案 我们应该调用 setFilte
我在使用 Android 的 DownloadManager 和 WebView 时遇到问题。有几个链接可以返回为当前用户生成的文件(PDF 等)。这些链接仅适用于登录用户,因此我将身份验证 cook
我想创建一个自定义 DownloadManager 类,我想在其中修改类在下载和其他内容期间发送的通知。有可能这样做还是我疯了?我的主要动机是在关闭应用程序时显示我的自定义下载通知。目前我正在使用禁用
我刚开始在 android 中使用 downloadmanager。我正在使用 genymotion 模拟器。 我正在尝试使用 downloadmanager 下载 mp3 文件。我想知道下载后文件存
我有下载多个图像和视频的要求,并且要求需要“一次”下载,因此实际上不需要任何缓存,这就是我不使用 Volley 的原因。视频 Volley 可能很昂贵。 接下来,我偶然发现了内置 Android 的
我正在使用 downloadManager,但它没有下载任何内容。当我开始下载文件时,它被放置在队列列表中并且永远不会开始下载。这是我的代码: webView.setDownloadListener(
我有一个 DownloadManager 来下载视频,以便我可以使用播放器播放。但是当我开始下载的时候,它生成了未完成的.mp4文件,所以当我在下载完成之前尝试播放时,会显示错误,是否可以在下载完成之
我在尝试处理下载的 .mp3 文件的通知点击事件时遇到问题。我已经注册了以下内容: DownloadManager.ACTION_NOTIFICATION_CLICKED - 我仅在单击当前正在下
我遇到以下问题:每当我使用 DownloadManager 下载文件时,它都会被下载两次(以“filename.extension”和“filename-1.extension”的形式保存)。这是我的
假设我要下载这个文件(随机文件): http://www.analysis.im/uploads/seminar/pdf-sample.pdf 这是我的代码: DownloadManager.Requ
我在我的应用程序中使用 DownloadManager 从 Internet 下载文件。这是我的代码。 DownloadManager downloadManager = (DownloadManag
我正在使用下载管理器 从我的服务器下载图像。 它可以很好地下载文件并将其放在我想要的位置。但出于某种原因,通知一直存在,我似乎无法删除它。下载管理器的代码如下: mDownloadManager =
每当我尝试通过下面的代码下载任何文件时 dm = (DownloadManager) context.getSystemService(context.DOWNLOAD_SERVICE); reque
我想得到这样的一些: 但我不知道如何获得百分比。 我读过这篇文章: Post 1 Post 2 Other web 但是我还没有得到什么好的结果=( ¿有什么想法吗? 我可以获得文件的总大小和下载的字
在我的 Android 应用程序中,我使用系统下载管理器下载照片,收到照片后我会处理它,然后我需要将它移动到另一个位置。如果我只是复制它,它工作正常,如果我尝试移动它/删除它,我会得到一个关于它无法移
我是一名优秀的程序员,十分优秀!