-2

In my application I'm downloading an image file. I want to show the download speed on a progress bar for the download.

How is it possible through AsyncTask Concept?

  • Something to start with http://www.androidhive.info/2012/04/android-downloading-file-by-showing-progress-bar/ – rohitanand Mar 17 '17 at 08:40
  • 1
    have you tried to google anything from your end. there are lots of answer available to this question. – Mohammad Tauqir Mar 17 '17 at 08:41
  • @Tauqir i have tried since for three days.but it show like 20% 23/100. i want to show it like kb/s. – Hassan jan Mar 17 '17 at 08:50
  • ask your question clearly and provide links that you have followed so far. if your question is not clear and also if it is common then for sure it will attract down voting. – Mohammad Tauqir Mar 17 '17 at 09:05
  • Next time i will try my best. Actually i am new here i know it is a little bit problem but i am confused. My file is Download and save in an External Directory properly. But i want to show measure the downloading speed of a file instead of percentage. @mcatta give me some tutorial i will try it.But if you have any information please suggest me i will be very thank full. – Hassan jan Mar 17 '17 at 09:29

2 Answers2

0

See the code snippet

 public static class MyDownloadTask extends AsyncTask<Void, Integer, Void> {

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
        // receive the published update here
        // progressBar.setProgress(values[0]);
    }

    @Override
    protected Void doInBackground(Void... params) {
        // publish your download progress here
        // publishProgress(10);
        return null;
    }
}
alijandro
  • 11,627
  • 2
  • 58
  • 74
-1

With this example you can set download speed on your progressdialog

public class AsyncDownload extends AsyncTask<Void, Double, String> {

    ProgressDialog progressDialog;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        progressDialog = new ProgressDialog(MainActivity.this);
        progressDialog.setMessage("Speed: " + 0.0);
        progressDialog.show();
    }

    @Override
    protected String doInBackground(Void... voids) {

        // AsyncDownload

        Double speed = 0.0;

        // Calculate speed
        publishProgress(speed);

        return null;
    }

    @Override
    protected void onProgressUpdate(Double... values) {
        super.onProgressUpdate(values);

        progressDialog.setMessage("Speed " + values[0]);
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
    }
}

to calculate download speed you can use this example Measuring Download Speed Java

Community
  • 1
  • 1
mcatta
  • 481
  • 5
  • 12