- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 downloadManager,但它没有下载任何内容。当我开始下载文件时,它被放置在队列列表中并且永远不会开始下载。这是我的代码:
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, final String contentDisposition, final String mimeType, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
//------------------------COOKIE!!------------------------
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType));
DownloadManager dm = (DownloadManager) activity.getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(activity.getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show();
}
});
如果我调试,所有值似乎都是正确的。此代码适用于 Android 6.0,但当我尝试使用 Android 7.0 时它不起作用。
有什么帮助吗?
非常感谢!!
最佳答案
您是在请求 WRITE_EXTERNAL_STORAGE 权限吗?
关于android - DownloadManager 不开始下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47295687/
我有一个使用 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 应用程序中,我使用系统下载管理器下载照片,收到照片后我会处理它,然后我需要将它移动到另一个位置。如果我只是复制它,它工作正常,如果我尝试移动它/删除它,我会得到一个关于它无法移
我是一名优秀的程序员,十分优秀!