Ravi
Ravi

Reputation: 151

Android API for Pause/Resume download

Does Android provide an API for pausing / resuming downloads (other than download manager)?

I have a task to download large size of file using background service. I have implemented the background services.

But if the network disconnected while the file is being downloaded the file gets corrupted, even if I try to resume from the same place where the previous download stopped. Does Android provide any API for resume the download process from where its left, so that the process will continue from the same place even if the network is disconnected and reconnected?

Upvotes: 0

Views: 1751

Answers (1)

Neeraj Kumar
Neeraj Kumar

Reputation: 943

For pause-resume downloads make sure that your server supports resumable downloads. Then You have to perform following steps:

  • First Check if the file exists or Not
  • If File exists then set the following propery on connection object
    connection.setRequestProperty("Range", "bytes=" + bytedownloaded + "-");
  • If file doesn't exists start a fresh download.

Or you can try an open source library which I have not tried

https://github.com/yingyixu/android-download-manager

Upvotes: 2

Related Questions