我有一个应用程序,它使用 Android 的DownloadManager将文件下载到外部文件存储(SD 卡)上的文件夹中。这通常可以正常工作,但有一些来源会导致 DownloadManager 在完成下载文件时将其丢弃。源文件的一个很好的例子是:
http://traffic.libsyn.com/hdtvpodcast/HDTV-2012-06-01.mp3
看起来问题可能只是来自 libsyn.com 的文件,但我并不肯定。我四处寻找改变 DownloadManager 处理文件保存方式的方法,但在类中找不到任何选项。
这是我将 URL 排入队列以供下载的位置:
request = new Request(Uri.parse(currUrl));
external = Uri.fromFile(externalFile);
request.setDestinationUri(external);
request.setVisibleInDownloadsUi(false);
request.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_HIDDEN);
currDownloadId = dm.enqueue(request);
使用以下命令创建文件位置:
Environment.getExternalStorageDirectory().getAbsolutePath() +
File.separator + "Podcatcher" + File.separator + "Feeds" + File.separator +
[int] + File.separator + [int] + [string extension];
当我从 DownloadManager 查询 DownloadManager.COLUMN_LOCAL_FILENAME 列时,结果是这样的:
/mnt/sdcard/Podcatcher/Feeds/19/225.mp3
大多数文件都很好并且在下载后仍然存在,但在这种情况下不是。关于如何在下载文件后强制 DownloadManager 离开文件的任何想法?
编辑:我没有提到,当我从浏览器下载此文件时使用独立的下载管理器时,它在下载结束时报告失败。也许我唯一的解决方案是从头开始下载它,而不使用 DownloadManager?