Pregunta

I'm trying to download the following file using DownloadManager:

http://loopstream01.apa.at/?channel=fm4&ua=flash&id=2013-10-05_1902_tl_54_4DDSat1__9778.mp3

The code looks like this:

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(asset.url));
request.setDescription("");
request.setTitle(asset.name);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "test");
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);

The download manager always fails to download the file with the following error message:

Aborting request for download 123: http error 206

Since 206 means partial content and this always requires a range in the http request I added

 request.addRequestHeader("Range", "bytes=0-1000");

to download the first 1000 bytes but the error message stays the same and nothing is downloaded. :(

Edit When I run the same code on an Android 4.2 device I'm getting the following message:

10-09 21:22:41.461: I/DownloadManager(2379): Download 231 starting 10-09 21:22:41.692: W/DownloadManager(2379): Aborting request for download 231: Expected OK, but received partial 10-09 21:22:41.712: I/DownloadManager(2379): Download 231 finished with status CANNOT_RESUME

¿Fue útil?

Solución

It appears as though the android download manager handles a 206 resume response if it believes it is resuming an earlier download.Otherwise it will assume the response is invalid. Explicit range requests inserted through addRequestHeader will not work.

Here's the download thread code for 4.3.1: https://android.googlesource.com/platform/packages/providers/DownloadProvider.git/+/android-4.3.1_r1/src/com/android/providers/downloads/DownloadThread.java

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top