I am using an external library to download files from Mega but I need a progressbar to display the duration of the download to the user. I have read a lot of progressbar related articles on stackoverflow but the problem is that I don't know what take so long in my code to add a progress bar.
Where and how do I have to add a progressbar to display the download status?
try {
URLConnection urlConn = new URL(file_url).openConnection();
print(file_url);
is = urlConn.getInputStream();
while ((read = is.read(buffer)) > 0) {
cos.write(buffer, 0, read);
}
} finally {
try {
cos.close();
if (is != null) {
is.close();
}
} finally {
if (fos != null) {
fos.close();
}
}
}
print("Download finished");
}