1

I wrote some library and it should load 3-5Mb files sometimes. I tried to use HttpURLConnection but I can't restore download with it if connection was lost from the last place. Also I tried DownloadManager, but it requires DOWNLOAD_WITHOUT_NOTIFICATION, which is unacceptable. Without it, it show load icon it top right corner, which is unacceptable also. I can't use third-party libraries also.

Are there any code sample how to force to work HttpURLConnection on poor connection (EDGE, overloaded servers) or some other open source library which code I can integrate?

anber
  • 3,463
  • 6
  • 39
  • 68
  • Related: http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog – Mister Smith Jan 12 '16 at 11:55

1 Answers1

1

Have a look at Volley. It allows custom retry policies for a request. You can instantiate a customized DefaultRetryPolicy and set it to your request using setRetryPolicy.

Be careful, because Volley caches the whole downloaded chunk in memory.

There might be other libraries out there, so check them out before rolling your own solution.

If nothing else suits your needs, you could pipe your HTTPUrlConnection stream to a file stream and write as you download. You would need to code the logic to manage the download state by yourself. First you would need to know in advance the size of the file to download (if your server sends you the "Content-Length" header), and to resume a partial failed download you would open a new connection to the same file and request from the last downloaded byte using http ranges.

Mister Smith
  • 27,417
  • 21
  • 110
  • 193
  • I tried Volley, but was not success - it returns onErrorResponse null, and before that `BasicNetwork.performRequest: Unexpected response code 200` – anber Jan 12 '16 at 12:26
  • Now I'm testing this few libraries, hope I find something - https://android-arsenal.com/tag/179 – anber Jan 12 '16 at 12:26