You need to send a file to the server and at the time of sending ProgresBar should appear and show the percentage of sending.

I found a few examples of how this can be done, only on the condition that the file is loaded onto the device, but not vice versa.

Here is the standard file upload code

 public static JSONObject sentJsonToServer(final URL url, final byte[] data, final String newValue) { ExecutorService ex = Executors.newCachedThreadPool(); Future<JSONObject> objectFuture = ex.submit(new Callable<JSONObject>() { @Override public JSONObject call() throws Exception { BufferedOutputStream bos = null; HttpURLConnection urlConnection = null; try { urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestProperty("Content-Type", newValue); urlConnection.setRequestMethod("POST"); urlConnection.setDoInput(true); urlConnection.setDoOutput(true); urlConnection.connect(); bos = new BufferedOutputStream(urlConnection.getOutputStream()); bos.write(data); bos.flush(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (bos != null) { bos.close(); } } catch (IOException e) { e.printStackTrace(); } } // returns POST request if (urlConnection != null) { return getJSONFromUrl(urlConnection); } else { throw new NullPointerException(); } } }); JSONObject responseJson = null; try { responseJson = objectFuture.get(); } catch (InterruptedException | ExecutionException | NullPointerException e) { e.printStackTrace(); } System.out.println("LAST JSOOOOOOOOOOON!!!!!!!!!!!!!!! " + responseJson); return responseJson; } 

I understand that I can take for a maximum the total number of byte[] that I am preparing to send, but how can I get the number of bytes that have already been sent, so that I can calculate the percentage of the difference already sent?

    0