Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Download Progress

Tags:

I want to know the progress of some download.
When I'm getting some resource from the internet, like this:

        String myFeed = request.getURI().toString();         URL url = new URL(myFeed);         URLConnection connection = url.openConnection();         HttpURLConnection httpConnection = (HttpURLConnection) connection;         int responseCode = httpConnection.getResponseCode();         if (responseCode == HttpURLConnection.HTTP_OK) {              InputStream in = httpConnection.getInputStream();             // Process the input stream         } 

When "InputStream in = httpConnection.getInputStream();" is called,
all the content of the file is downloaded at once.

If I use:

        htttpResponse = httpClient.execute(httpRequestBase); 

The problem is the same.

How can I detect the actual progress of the download?

Thank you all!

like image 522
Tsimmi Avatar asked Jan 20 '10 10:01

Tsimmi


People also ask

How do I check download progress on Android?

Generally, the progress indicators in android are implemented by using the ProgressBar class. To display the progress indicators in our app, we need to add the progress bar to our notification by calling setProgress(max, progress, false) method and then issue the notification.

How do I see download progress in notification bar?

Go to Settings - Apps - All Apps - Chrome - Notifications. Now enable show notification button and in sub categories enable notification for downloads. Follow same procedure for any other browser.

How do I stop Android from downloading in progress?

To prevent file downloads, go to Settings > Apps & notifications, and tap the app name in the list. Tap Permissions and toggle Storage to off.


1 Answers

I think this has been answered here.

In a nutshell: use the "Content-Length" which should be in the header fields.

EDIT: sorry, I wasn't answering the question exactly. Basically once you know the expected total content length then you can keep track of how much data you have received and calculate the percentage complete.

See also: How to create a download manager

like image 175
GaZ Avatar answered Sep 29 '22 15:09

GaZ