Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Download a single file in many parts

I developing an application like Internet Download Manager for Android.

I want to know how to download different parts of file in Android as it is done in IDM.

How can I get the metadata of file before download and how to download files in parts?

There is no username-password or any restrictions in downloading... just simple download by url.

like image 663
Rahul Sharma Avatar asked Oct 16 '12 18:10

Rahul Sharma


1 Answers

Assuming you're using HTTP for the download, you'll want to use the HEAD http verb and RANGE http header.

HEAD will give you the filesize (if available), and then RANGE lets you download a byte range.

Once you have the filesize, divide it into roughly equal sized chunks and spawn download thread for each chunk. Once all are done, write the file chunks in the correct order.

EDIT:

If you don't know how to use the RANGE header, here's another SO answer that explains how: https://stackoverflow.com/a/6323043/1355166

like image 124
gcochard Avatar answered Oct 23 '22 10:10

gcochard