Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't resume download

I want to download a big (zip) file from my server. It's about 440MB. I'm using android download service.

Here is my code:

DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(Uri.parse(SERVER_PATH));
request.setTitle(getString(R.string.title_download));
request.setDescription(getString(R.string.desc_download));
File mapDir = new File(Environment.getExternalStorageDirectory() + DEVICE_PATH_PART);
File mapPartFile = new File(Environment.getExternalStorageDirectory() + DEVICE_PATH_PART + MAP_PACKFILE + EXT_INPROGRESS);
request.setDestinationUri(Uri.fromFile(mapPartFile));
enqueue = dm.enqueue(request);

Download start fine. I can see my file in download manager. But when occurs some network problems (connection break), download finish with error 1008 and partial file is removed from my directory. And this is my problem and question: How can I force download service to not remove partially file from my destination directory, in order to resume download process ?

The side question or problem is: when I downloading 440meg file from my app, then download process is breaks many times (with cant resume error and after that with no possibility do resume download). But if I download same file through download manager application directly in android, everything is ok. And I don't know why. The only error I'm getting in receiver is 1008 about cant resume. Is there anybody with same problem?

Thank you.

like image 551
Rado Dr. Avatar asked Dec 25 '13 21:12

Rado Dr.


People also ask

How do I resume a stuck download?

You can type chrome://downloads in Chrome address bar, and press Enter to open Chrome Download Manager. Alternatively, you can also press Ctrl + J to open this page on Windows. Next find the failed downloading and click Resume button to resume the interrupted download from where it left off in Chrome.

Why does my download stop before it is finished?

Sometimes, the downloads stop due to the connection with the server is temporarily interrupted when the bandwidth hits its limit. It's possible that you will not be able to resume the download files if you are using a browser to download such files. However, most of the time, employing a Download Manager can help.

Can I resume download after shutdown?

If the SERVER that is providing the download supports resuming downloads, then after you resume from hibernation, you should have no issues resuming the download. After you pause the download, there is no need to touch Chrome. Just pause, and hibernate. By that I mean, don't close Chrome.


1 Answers

Your server must return an ETag header, which is used by DownloadManager for identifying the downloading files. If the download process is interrupted, the DownloadManger requests a partial download for resuming on the last downloaded position. This request contains additional headers: Content-Range for the range and If-Match with the value of the received ETag. The server must respond with the requested range and with the HTTP status code 206. Check your server logs and compare them to the ADB output.

like image 143
artkoenig Avatar answered Nov 07 '22 13:11

artkoenig