Android : Download a single file in many parts

2019-04-26 21:18发布

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.

1条回答
【Aperson】
2楼-- · 2019-04-26 22:12

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

查看更多
登录 后发表回答