In my application downloading loads of files from web they were around 200Mb files(Zipped). How do I download files programmatically in Android? Actually my concern is about performance of code. How do I handle errors and network problem in between?
Go to the webpage where you want to download a file. Touch and hold what you want to download, then tap Download link or Download image. To see all the files you've downloaded to your device, open the Downloads app.
How to Use Internet Download Manager. From the main interface, you can see multiple control buttons. To download new file, simply click Add URL and paste the link to the file that you wish to download. Start downloading by clicking the Start/Resume button.
Here's some code that I recently wrote just for that:
try {
URL u = new URL("http://your.url/file.zip");
InputStream is = u.openStream();
DataInputStream dis = new DataInputStream(is);
byte[] buffer = new byte[1024];
int length;
FileOutputStream fos = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/" + "file.zip"));
while ((length = dis.read(buffer))>0) {
fos.write(buffer, 0, length);
}
} catch (MalformedURLException mue) {
Log.e("SYNC getUpdate", "malformed url error", mue);
} catch (IOException ioe) {
Log.e("SYNC getUpdate", "io error", ioe);
} catch (SecurityException se) {
Log.e("SYNC getUpdate", "security error", se);
}
This downloads the file and puts it on your sdcard.
You could probably modify this to suit your needs. :)
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