Reputation: 93
I have an app that downloads files using Android's DownloadManager to a folder on the external file storage (SD card). This normally works fine, but there are some sources that cause the DownloadManager to trash the file when it finishes downloading it. A good example of a source file is:
http://traffic.libsyn.com/hdtvpodcast/HDTV-2012-06-01.mp3
It looks like maybe the problem is only with files from libsyn.com, but I'm not positive. I've looked around for ways to change how DownloadManager handles saving files, but can't find any options in the class.
This is where I enqueue the URL for download:
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);
The file locations are created using this:
Environment.getExternalStorageDirectory().getAbsolutePath() +
File.separator + "Podcatcher" + File.separator + "Feeds" + File.separator +
[int] + File.separator + [int] + [string extension];
Which turns out to be something like this when I query DownloadManager.COLUMN_LOCAL_FILENAME column from DownloadManager:
/mnt/sdcard/Podcatcher/Feeds/19/225.mp3
Most of the files are fine and persist after download, but not in this case. Any ideas about how I can force DownloadManager to leave the file after it is downloaded?
EDIT: I neglected to mention that when I use the standalone Download Manager when downloading this file from a browser that it reports failed at the end of the download. Perhaps my only solution is to download it from scratch, without DownloadManager?
Upvotes: 4
Views: 2769
Reputation: 3599
try please followed code - worked for me:
request.setMimeType(application/octet-stream);
Upvotes: 1