chiranjib
chiranjib

Reputation: 5308

Handle download of files on network failure

I am creating an Android mobile application where I have the following requirements.

i>When the end-user clicks on any of the list items(thumbnail images) displayed on the screen , the video corresponding to the image starts to download from the server & ultimately the video is saved on a specific location of the mobile device.

Now , when there is a network failure , the download fails but the requirement is that , from the next time onwards , the downloading of the video file should start from the same place from where it was disconnected.

Kindly provide me the suggestions/tips/sample code to how to maintain the state of the downloads so that it gets started from the same place next time.

Thanks in advance.

Warm Regards,

CB

Upvotes: 0

Views: 437

Answers (1)

Chen Zhuo
Chen Zhuo

Reputation: 91

I know theory but not code.

  1. you should record where the download item stopped, say offset 1234 from beginning
  2. set “Range: bytes=1234-” as a header parameter to the request when continue to download the item

use HttpRequest.setHeader ("Range", "bytes=1234-") to set the header if you are using org.apache.http.

Upvotes: 1

Related Questions