How to get progress while downloading file via HttpRequest Android?

Good afternoon. Was faced with another problem. Upload a file to the application under Android using HttpRequest in AsyncTask and I would like to show users the loading process. Example: file Download: 50%

How to update a counter in AsyncTask I know, but how in the HttpRequest to download progress of the file on the server?
July 8th 19 at 15:39
1 answer
July 8th 19 at 15:41
I once implemented something similar, but without HttpRequest
Can you help

 protected Bitmap doInBackground(String... params) {
 int count;
 try {

 URL URL = new URL(params[0]);
 URLConnection connect = url.openConnection();

 int lengthOfFile = connect.getContentLength();
 input = new BufferedInputStream(url.openStream());
 output = new FileOutputStream("sdcard/downloaded_photo.jpg");

 byte data[] = new byte[1024];

 long total = 0;

 while ((count = != -1) {
 total += count;
 publishProgress("" + (int) ((total * 100) / lengthOfFile));
 output.write(data, 0, count);


Find more questions by tags AndroidJava