I want to download a file(MP4) by clicking on the list view Items
Please give guidance on this!
I want to download a file(MP4) by clicking on the list view Items
Please give guidance on this!
onItemClickListener
write code to download any file,
int count;
try {
URL url = new URL("YOUR_URL");
URLConnection conection = url.openConnection();
conection.connect();
int lenghtOfFile = conection.getContentLength();
InputStream input = new BufferedInputStream(url.openStream(), 8192);
OutputStream output = new FileOutputStream("DOWNLOAD_LOCATION");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
e.printStackTrace();
}
Note : You have to write this code in AsyncTask
and android.permission.INTERNET
is necessary.