Update a progressbar

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Update a progressbar

Postby pratik goswami » Fri Oct 24, 2008 1:26 pm

Hello friends...

I am developing an application to upload multiple photos to server. I want to update progress bar and title according to response message coming from server. Passing photos to server is in a for loop(as shown in code). Progressbar and Title are being updated at last time of executing For loop. I want to update progress bar and title at every time of response.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. //FOR loop to send photos to server.
  2.         for (i = 0; i < ImgNm.length; i++) {
  3.         //Response message after uploading a photo
  4.                 String msg = addPhoto(ImgNm[i], path[i], i + 1,
  5.                 ImgNm.length);
  6.         //If msg is OK then porgressbar would update
  7.                 if (!msg.equals("Photo added successfully")) {
  8.                         break;
  9.                 } else {
  10.                         //Method to Set progressbar and Title
  11.                         mProgressStatus = (10000 / (ImgNm.length) * i);                                        
  12.                         setprogress(ImgNm[i], mProgressStatus);
  13.                         }
  14.                 }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


And here are the Methods - addPhoto and setprogress

Method to Upload photo

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public synchronized String addPhoto(String fileNm, String filePath,
  2.                         int current, int all) {
  3.  
  4.                 try {
  5.                         String url = "http://192.168.5.231:8084/Pratik/Photo?Action=Addnew";
  6.                        
  7.                         connectURL = new URL(url);                     
  8.                         HttpURLConnection conn = (HttpURLConnection) connectURL
  9.                                         .openConnection();                     
  10.                         conn.setDoInput(true);
  11.                         conn.setDoOutput(true);
  12.                         conn.setUseCaches(false);
  13.                         conn.setRequestMethod("POST");
  14.                         conn.setRequestProperty("Connection", "Keep-Alive");
  15.                         conn.setRequestProperty("Content-Type",
  16.                                         "multipart/form-data;boundary=" + boundary);
  17.                         conn.setConnectTimeout(connectionTimeout);                     
  18.                         DataOutputStream dos = new DataOutputStream(conn.getOutputStream());                   
  19.                         FileInputStream fileInputStream = new FileInputStream(filePath);
  20.                         byte[] buffer = new byte[fileInputStream.available()];
  21.                         int bytesRead = fileInputStream.read(buffer);                  
  22.                         dos.write(buffer);
  23.                         dos.flush();                   
  24.                         fileInputStream.close();
  25.                         dos.flush();
  26.  
  27.                         InputStream is = conn.getInputStream();
  28.                         BufferedReader bf = new BufferedReader(new InputStreamReader(is));
  29.                         response = bf.readLine();
  30.  
  31.                         dos.close();
  32.                         Log.i(tag, "response is:::::" + response);
  33.                 } catch (MalformedURLException ex) {
  34.                         Log.e(tag, "error: " + ex.getMessage(), ex);
  35.                 } catch (IOException ioe) {
  36.                         Log.e(tag, "error: " + ioe.getMessage(), ioe);
  37.                 }
  38.                 notifyAll();
  39.                 return response;
  40.         }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


AND method to set progress bar and title

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public synchronized void setprogress(String title, int value) {        
  2.                 setProgress(value);
  3.                 setTitle(title);
  4.                 notifyAll();
  5.         }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4



Thanks in advance
Pratik
pratik goswami
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Sep 22, 2008 2:54 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests