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?
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.
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.
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.
◤ 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With