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.
Using java Syntax Highlighting
- //FOR loop to send photos to server.
- for (i = 0; i < ImgNm.length; i++) {
- //Response message after uploading a photo
- String msg = addPhoto(ImgNm[i], path[i], i + 1,
- ImgNm.length);
- //If msg is OK then porgressbar would update
- if (!msg.equals("Photo added successfully")) {
- break;
- } else {
- //Method to Set progressbar and Title
- mProgressStatus = (10000 / (ImgNm.length) * i);
- setprogress(ImgNm[i], mProgressStatus);
- }
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
And here are the Methods - addPhoto and setprogress
Method to Upload photo
Using java Syntax Highlighting
- public synchronized String addPhoto(String fileNm, String filePath,
- int current, int all) {
- try {
- String url = "http://192.168.5.231:8084/Pratik/Photo?Action=Addnew";
- connectURL = new URL(url);
- HttpURLConnection conn = (HttpURLConnection) connectURL
- .openConnection();
- conn.setDoInput(true);
- conn.setDoOutput(true);
- conn.setUseCaches(false);
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Connection", "Keep-Alive");
- conn.setRequestProperty("Content-Type",
- "multipart/form-data;boundary=" + boundary);
- conn.setConnectTimeout(connectionTimeout);
- DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
- FileInputStream fileInputStream = new FileInputStream(filePath);
- byte[] buffer = new byte[fileInputStream.available()];
- int bytesRead = fileInputStream.read(buffer);
- dos.write(buffer);
- dos.flush();
- fileInputStream.close();
- dos.flush();
- InputStream is = conn.getInputStream();
- BufferedReader bf = new BufferedReader(new InputStreamReader(is));
- response = bf.readLine();
- dos.close();
- Log.i(tag, "response is:::::" + response);
- } catch (MalformedURLException ex) {
- Log.e(tag, "error: " + ex.getMessage(), ex);
- } catch (IOException ioe) {
- Log.e(tag, "error: " + ioe.getMessage(), ioe);
- }
- notifyAll();
- return response;
- }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
AND method to set progress bar and title
Using java Syntax Highlighting
- public synchronized void setprogress(String title, int value) {
- setProgress(value);
- setTitle(title);
- notifyAll();
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
Thanks in advance
Pratik


