1

how to check the amount of data in each time uploaded to the server, this is my code which I call inside a AsyncTask

public  String conxDatosInPost(String Direccion, ArrayList<NameValuePair> Parametros) throws Exception {
  BufferedReader in = null;
  try {
    HttpClient client = ClienteHttp();
    HttpPost request = new HttpPost(Direccion);
    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(Parametros);
    request.setEntity(formEntity);
    HttpResponse response = client.execute(request);
    //long logitud = response.getEntity().getContentLength();
    in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    StringBuffer sb = new StringBuffer("");
    String line = "";
    String NL = System.getProperty("line.separator");
    while ((line = in.readLine()) != null) {
     sb.append(line + NL);
    } 
    in.close();
    String result = sb.toString();
    Log.d("El resultado de cnxposin es :-----------  ",  result +"fn");
    return result;
  } finally {
    if (in != null) {
     try {
      in.close();
     } catch (IOException e) {
      e.printStackTrace();
     }
    }
  }
}

This is my class CLienteHttp();

private  HttpClient ClienteHttp() {
  if (mHttpCliente == null) {
     public static final int HTTP_TIMEOUT = 30 * 1000; // milliseconds
    mHttpCliente = new DefaultHttpClient();
    final HttpParams params = mHttpCliente.getParams();
    HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
    ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
  }
  return mHttpCliente;
}

And this is my class asyncTask

public class NuevoPostImagen extends AsyncTask<String, Integer, String>{
  @Override
  protected String doInBackground(String... params) {
    objAcceso = new AccesoBd();
    String jsRes="";
    SharedPreferences userDetails = getParent().getSharedPreferences("MisPreferencias", MODE_PRIVATE);
    ArrayList<NameValuePair> ParametrosDeEnvio = new ArrayList<NameValuePair>();
    ParametrosDeEnvio.add(new BasicNameValuePair("from",Integer.toString(userDetails.getInt("Id",0))));
    ParametrosDeEnvio.add(new BasicNameValuePair("idrecurso",Integer.toString(idEvento)));
    ParametrosDeEnvio.add(new BasicNameValuePair("texto","nada"));
    ParametrosDeEnvio.add(new BasicNameValuePair("titulo",txtFTitulo.getText().toString()));
    ParametrosDeEnvio.add(new BasicNameValuePair("imageFile",sImagenBsase64));
    try{
      //here 
      String jes=objAcceso.conxDatosInPost(params[0],ParametrosDeEnvio);
      jsRes = "ok";
    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
    }finally{return jsRes;}
  }
  @Override
  public void onProgressUpdate(Integer... args){
    Pro.setProgress(args[0]);
  }
  @Override
  protected void onPostExecute( String result) {
    Pro.dismiss();
    if (result.toString().equals("ok")){
      LlenarEvento();
      dOpciones.dismiss();
      dHacerFoto.dismiss();
    }
  }
  @Override
  protected void onPreExecute() {
    Pro = ProgressDialog.show(getParent(), "", "Enviando",true,true);
    Pro.setCancelable(false);
  }
}

Can I update my progress bar with the existing code?

Once the cliente.execute (httpost).

I wonder how I can put a listener or something to check the number of bytes uploaded being updated every second or every time you upload them? I need to update my progress bar, according to the quantity that has been uploaded.

Please, I can help?

Delari Jesus
  • 411
  • 6
  • 22

1 Answers1

0

You can use async task for this. you have to over ride 3 methods.

doinbackground() onpreexecute() onpostexecute() onProgressUpdate i think this will help u to understand hw to do it . How to implement file upload progress bar in android

Community
  • 1
  • 1
android.fryo
  • 1,469
  • 1
  • 14
  • 18
  • this is not enough for me, I have to check what is loaded in every second, once done client.execute (httpost) – Delari Jesus Nov 30 '12 at 17:41
  • this is not the answer to my question, but thanks anyway, This tells me that you do not really work – Delari Jesus Nov 30 '12 at 17:50
  • 1
    you won't get % of file uploaded by calling client.execute(). you can see the implementation here http://stackoverflow.com/questions/7057342/how-to-get-a-progress-bar-for-a-file-upload-with-apache-httpclient-4 – android.fryo Nov 30 '12 at 17:52
  • I do not need to save anything in the Telegonus if not the server – Delari Jesus Nov 30 '12 at 18:05