Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best way to download a big file in android?

Tags:

android

I need to download a big file on my app (almost 2gb) and i was wondering what is the best way to do that and some libs to help me. First I looked the Android Asynchronous Http Library but I didn't find examples showing how to publish the progress or start, pause download. Then I don't know if should I use this lib or just use a standart http commons. Other problem is, should I use a service to download my file??

Could you guys give a hint, how to do that?

like image 961
Victor Laerte Avatar asked Apr 02 '13 12:04

Victor Laerte


People also ask

How can I download big files faster on Android?

Install the AndroGET app from the Android Market. Launch it and tap the gear-shaped Settings icon in the top right. The simple settings are pretty good for most users, but you can easily change the default save folder, number of simultaneous downloads, and notifications. Tap Advanced to change proxy settings and more.

How can I download big files faster?

For very large size downloads (more than 2GB), we recommend that you use a Download Manager to do the downloading. This can make your download more stable and faster, reducing the risk of a corrupted file. Simply save the download file to your local drive.

How can I download a file greater than 4GB to a smartphone?

Please make sure that your storage location is saved as an SD card in the settings in our app. If you want to download files larger than 4GB, please change the storage location to internal storage or please transfer after dividing files smaller than 4GB. Then you will be able to download them.

How can I download bigger than 4GB SD card?

◤ 1. Formatting will cause data loss, so, if you choose to format the target device, please backup all data. ◤ 2. If you're going to use the SD card on Android, you may utilize the exFAT format, which removes size limitations and is far better suited for flash storage.


1 Answers

I've see you got a bunch of answer and none of them really answers it from a holistic point of view.

To download a 2k or 2gb file the actual code is the same using some type of connection handler and some type of input stream and output stream and usually wrapping the input stream with a buffered input stream. For that you can find infinite amount of java examples all around the web.

The trick here considering the Android platform is that because it's a lengthy operation, you shouldn't be doing it inside the activity life cycle at all.

Said that you have two options:

  • as you suggested you can create a Service, I would suggest you to use the IntentService as it seems to be a perfect fit for this case. The IntentService automatically spans a new thread, through the intent you pass the URL as a String and let the service download using the streams, etc.

  • another method that probably work well, but I've never personally used, is to use the DownloadManager that is available since Gingerbread. It shouldn't be difficult to call getSystemService(Context.DOWNLOAD_SERVICE) and call dwManag.enqueue(dwRequest);

hope it helps.

like image 117
Budius Avatar answered Sep 24 '22 13:09

Budius