i have problem with progressdialog to the, i want updating my progressdialog while duration of the connection.
This is my progressdialog
Pro = new ProgressDialog(getParent());
Pro.setMessage("Enviando");
Pro.setIndeterminate(false);
Pro.setMax(100);
Pro.setCancelable(false);
Pro.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
this my asynctask
private class NuevoPostVideo extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... params) {
objAcceso = new AccesoBd();
String jsRes= "";
SharedPreferences userDetails = getParent().getSharedPreferences("MisPreferencias", MODE_PRIVATE);
try{
File f = new File(sDireccionFoto);
FileBody bin = new FileBody(f);
StringBody from = new StringBody( Integer.toString(userDetails.getInt("Id",0)));
StringBody id_recurso = new StringBody(Integer.toString(idEvento));
StringBody titulo_body = new StringBody(txtVTitulo.getText().toString());
StringBody ficha = new StringBody("null");
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("imageFile", bin);
reqEntity.addPart("from",from);
reqEntity.addPart("idrecurso",id_recurso);
reqEntity.addPart("titulo", titulo_body);
reqEntity.addPart("ficha", ficha);
objAcceso.conxDatosInPost(params[0],reqEntity);
jsRes="ok";
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{return jsRes;}
}
@Override
protected void onPostExecute( String result) {
if (result.equals("ok")){
SharedPreferences userDetails = getParent().getSharedPreferences("MisPreferencias", MODE_PRIVATE);
DetalleEvento objd = new DetalleEvento();
objd.setTipo(1);
objd.setFecha(objAcceso.FechaActualinglesa());
objd.setTituloPost(sTituloPost);
objd.setImagen(btmImagenElegida);
objd.setUrl(sDireccionFoto);
objd.setAutor(userDetails.getString("Nombre","Usted"));
objAdapterDetalles.arrayDatos.add(0,objd);
objAdapterDetalles.notifyDataSetChanged();
lstDatos.setSelection(1);
dOpciones.dismiss();
dHacerVideo.dismiss();
}
Pro.dismiss();
prgVProgreso.setVisibility(View.INVISIBLE);
}
@Override
protected void onPreExecute() {
//prgVProgreso.setVisibility(View.VISIBLE);
Pro.show();
//Pro.incrementProgressBy(10);
}
@Override
public void onProgressUpdate(Integer... args){
Pro.setProgress(args[0]);
}
}
this my function of conexion “Look at this line of my doinbhackgroud” (objAcceso.conxDatosInPost(params[0],reqEntity); )
public String conxDatosInPost(String Direccion, MultipartEntity Parametros) throws Exception {
BufferedReader in = null;
try {
HttpClient client = ClienteHttp();
HttpPost request = new HttpPost(Direccion);
request.setEntity(Parametros);
HttpResponse response = client.execute(request);
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();
}
}
}
}
¿as I can do to update my progress dialog While the connection lasts ?
UPDATE
I have problems to calculate the size of the file to insert (video in this case) and to see the progress of the upload to the server at each times
find not the way to do this
I would like to know if there was the possibility of some listener progresslistener style?
please could help me or give me a hint
ultimately solve my problem as follows
this is how my code is
and this is my new class