Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何获取下载速度 #54

Open
EvlinLee opened this issue Feb 6, 2017 · 4 comments
Open

如何获取下载速度 #54

EvlinLee opened this issue Feb 6, 2017 · 4 comments

Comments

@EvlinLee
Copy link

EvlinLee commented Feb 6, 2017

No description provided.

@salehmosleh
Copy link

Please write english.

@EvlinLee
Copy link
Author

EvlinLee commented Feb 6, 2017

@salehmosleh how to get the speed?

@salehmosleh
Copy link

here is an example , update CallBack Request class , method onProgress in your service:

    private long mLastTime=0;
    private long _last_finished = 0;
    private DecimalFormat DF = new DecimalFormat("0.00")
    @Override
    public void onProgress(long finished, long total, int progress) {
        if (mLastTime == 0) {
            fifn.Status = FileInfo.STATUS_DOWNLOADING;
            mLastTime = System.currentTimeMillis();
            fifn.filesize = total;
            updateDB();
        }
        fifn.progress = progress;
        fifn.downloadPerSize = getDownloadPerSize(finished, total);
        fifn.Status = FileInfo.STATUS_DOWNLOADING;
        long currentTime = System.currentTimeMillis();

        if (currentTime - mLastTime > 800) {
            double downspeedn = (((double)(finished-_last_finished))/1024d)/0.80d;
            String downspeed =  DF.format(downspeedn);
            notify.setContentText("speed is  "+downspeed+"KB/s ...");
            notify.setProgress(100, progress, false);
            mLastTime = currentTime;
            _last_finished = finished;
            updateNotification(FileInfo.STATUS_DOWNLOADING);
            sendBroadCast();
            
        }
    }
   public String getDownloadPerSize(long finished, long total) {
          return (DF.format((float) finished / (1024 * 1024)) + "M/" +
                      DF.format((float) total / (1024 * 1024)) + "M");
  }

@EvlinLee
Copy link
Author

@salehmosleh thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants