Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7599623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:42:28+00:00 2026-05-30T22:42:28+00:00

I am trying to perform a http-get-request and show the download progress to the

  • 0

I am trying to perform a http-get-request and show the download progress to the user. I am familiar with the concept of AsyncTask, I also know how to use URLConnection together with BufferedInputStream to download a file in pieces while showing a progress AND I know how to execute a http-get-request and receive a HttpResponse:

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response = httpclient.execute(httpget);

But I just cannot figure out how to show a progress of the execute method. I found the method below. But what is all this copying from an InputStream to an OutputStream, after all data are already downloaded? I don’t want to see the progress of this copying process, but the progress of the HttpResponse! – Any suggestions? Where is my error in reasoning? I have the strong feeling that I missed something very important …

String sURL = getString(R.string.DOWNLOAD_URL) + getString(R.string.DATABASE_FILE_NAME);
HttpClient  httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(sURL);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
Header[] clHeaders = response.getHeaders("Content-Length");
Header header = clHeaders[0];
int totalSize = Integer.parseInt(header.getValue());
int downloadedSize = 0;
if (entity != null) {
    InputStream stream = entity.getContent();
    byte buf[] = new byte[1024 * 1024];
    int numBytesRead;

    BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(file));
    do {
        numBytesRead = stream.read(buf);
        if (numBytesRead > 0) {
            fos.write(buf, 0, numBytesRead);
            downloadedSize += numBytesRead;
            //updateProgress(downloadedSize, totalSize);
        }
    } while (numBytesRead > 0);
    fos.flush();
    fos.close();
    stream.close();
    httpclient.getConnectionManager().shutdown();
}

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:42:29+00:00Added an answer on May 30, 2026 at 10:42 pm

    That code looks fine. The InputStream is the stream of data that you’re downloading. As you download each chunk, you save that chunk into a file and update your progress. It’s not after the data is already downloaded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying create a ASMX webservice that can perform a HTTP GET request. I
I am trying to use the focusout( http://api.jquery.com/focusout/ ) function in jQuery, to perform
I'm trying to run the simplest python script to perform a http request and
I'm using ASIHTTP and trying to perform a GET request for a site: NSURL
I'm trying to perform an AJAX-request in a view, the user gives some input
I use Pinax, and I am trying to perform login test on account project,
I'm trying to perform a simple html request using jquery with the code below.
I'm trying to use livestream's extremely helpful mobile api found at http://www.livestream.com/userguide/?title=Mobile_API#Requesting_a_mobile_stream to make
I am trying to perform an ajax.get using jquery within document.ready . But the
I have application that received data via HTTP POST requests. I'm trying to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.