2

I am working with Android 3.0 and 3.1. I use the class AndroidHttpClient in my application and for the execute I use execute(HttpUriRequest).

I have a progress bar in the UI that I want to be updated while sending data. Is there any way to get notifications from the AndroidHttpClient about the progress of the data sending (I guess it doesn't send the whole buffer in one shot)?

Thanks

Yaniv
  • 3,321
  • 8
  • 30
  • 45

2 Answers2

1

To track the progress of data as it is sent to the server you have to wrap the underlying HTTP entity that is being sent. If you subclass HttpEntityWrapper and override writeTo() you can wrapper the OutputStream with a FilterOutputStream that is the stream being written to the server.

Nic Strong
  • 6,532
  • 4
  • 35
  • 50
  • I've wrapped the OutputStream class and overrrided the writeTo(). Now the data is splitted to a few parts and sent with a for loop. – Yaniv Sep 13 '11 at 07:04
  • And as each call to writeTo() is made you can call back to some listener where you implement the progress? – Nic Strong Sep 13 '11 at 08:16
0

i think you need AsyncTask example , may be it will help you ::

  private class xyz extends AsyncTask<Void, Void, Void> {
            private final ProgressDialog dialog = new ProgressDialog(tranning.this);
            @Override
            protected void onPreExecute() {
                this.dialog.setMessage("Please Wait...");
                this.dialog.show();

                // put your code which preload with processDialog  
            }

            @Override
            protected Void doInBackground(Void... arg0) {

                // put you code here


                return null;
            }
            @Override
            protected void onPostExecute(final Void unused) {
                //if (this.dialog.isShowing()) {
                //  this.dialog.dismiss();

                //}

            }
        }

and use it in your main class ::

 new xyz().execute();
katzenhut
  • 1,742
  • 18
  • 26
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133
  • 1
    If you find yourself pasting the same answer on several questions, there's a strong possibility that you should probably be flagging one as a duplicate instead. If the other question is merged into this one, the exact same answer would be duplicated. I'm not saying you provided a bad answer, but just be careful when posting the same one in several places. – Tim Post Sep 06 '11 at 09:14
  • i understand your approach, but maybe you should mention the `onProgressUpdate` - method in asynctask, since that one actually communicates the progress of the task. i cant find it in your answer. but it's a good approach, anyways. – katzenhut Apr 30 '15 at 12:01