Android : Download a single file in many parts

…衆ロ難τιáo~ 提交于 2019-12-07 01:09:29

问题


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:


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



来源:https://stackoverflow.com/questions/12921452/android-download-a-single-file-in-many-parts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!