Java 如何计算上传任务';s百分比
我在Java 如何计算上传任务';s百分比,java,android,upload,progressdialog,Java,Android,Upload,Progressdialog,我在UploadAsync类中有一个doFileUpload方法,它扩展了AsyncTask。 我想知道如何从以下代码计算上传任务的百分比,以使用publishProgress(“+值”)更新ProgressDialog 感谢我曾经遇到过类似的问题,我使用光标跟踪下载的字节,如下所述: 这就是我在应用程序中所做的 long total = 0; int lenghtOfFile=connection.getContentLength(); while ((count
UploadAsync
类中有一个doFileUpload
方法,它扩展了AsyncTask
。
我想知道如何从以下代码计算上传任务的百分比,以使用publishProgress(“+值”)更新ProgressDialog
感谢我曾经遇到过类似的问题,我使用光标跟踪下载的字节,如下所述:
这就是我在应用程序中所做的
long total = 0;
int lenghtOfFile=connection.getContentLength();
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
publishProgress(""+(int)((total*100)/lenghtOfFile));
// writing data to file
output.write(data, 0, count);
if (isCancelled()) break;
}
您可以在这里看到它:hereHttpURLConnection=null代码>
long total = 0;
int lenghtOfFile=connection.getContentLength();
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
publishProgress(""+(int)((total*100)/lenghtOfFile));
// writing data to file
output.write(data, 0, count);
if (isCancelled()) break;
}