我们可以为android.os.DownloadManager提供自定义通知吗? [英] Can we have Custom Notification for android.os.DownloadManager?

查看:105
本文介绍了我们可以为android.os.DownloadManager提供自定义通知吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在使用以下代码段通过 DownloadManager :

Currently I am using below code snippet to download a file using DownloadManager:

String servicestring = Context.DOWNLOAD_SERVICE;
                DownloadManager downloadmanager;
                downloadmanager = (DownloadManager) getSystemService(servicestring);
                Uri uri = Uri
                        .parse("some url here");
                DownloadManager.Request request = new Request(uri);

使用此代码,我得到以下通知.

Using this code I am getting below notification.

我的问题是,我们可以在此通知中添加一些交叉按钮,以便用户单击该按钮将取消下载吗?

预期输出:

(用户必须能够在单击该红叉图标时取消下载)

(user must be able to cancel download when click on this red cross icon)

请提出一些建议.谢谢

推荐答案

我们可以在此通知中添加一些十字按钮,以便用户单击该按钮将取消下载吗?

can we add some cross button in this notification so that if user click that button it will cancel download?

不直接.您的应用未显示Notification;您无法控制它的行为.

Not directly. That Notification is not being displayed by your app; you have no control over its behavior.

最可能的解决方案是不使用DownloadManager,而是自己下载内容.然后,您可以将任何内容显示为Notification.

The most likely solution is to not use DownloadManager, but instead download the content yourself. Then, you can display whatever you want as a Notification.

使用DownloadManager是中间立场,但要设置标志和权限以允许您请求不显示Notification的下载.然后,您可以拥有自己的Notification.不利之处是您可能无法复制系统提供的Notification的所有功能(例如,完成进度百分比指示器).

Middle ground would be to use DownloadManager but set up the flags and permissions to allow you to request downloads that do not display a Notification. Then, you can have your own Notification. The downside here is that you may not be able to reproduce all features of the system-supplied Notification (e.g., percent-complete progress indicator).

这篇关于我们可以为android.os.DownloadManager提供自定义通知吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆