【发布时间】:2016-02-25 11:55:29
【问题描述】:
我正在尝试在媒体下载时显示进度。 歌曲已正确下载并存储现在我想显示下载了多少 百分比。
所以任何人都可以帮助我。 这是我的代码:-
class DownloadFile extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... url) {
//............ declration and all
if (fsize != lenghtOfFile) {
int filesize = f.getAbsolutePath().length();
if (filesize != lenghtOfFile) {
InputStream input = new BufferedInputStream(url1.openStream());
OutputStream output = new FileOutputStream(f);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress("" + (int) ((total * 100) / lenghtOfFile));
// pDialog.setMessage( String.valueOf((int) ((total * 100) / lenghtOfFile)) +"Downloaded.");
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
}
//...... other code
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
//on post over
pDialog.dismiss();
}
@Override
protected void onPreExecute() {
//set Dialog
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Please wait song is Downloading...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
}
**所有的东西都运行良好.... 只是 我想显示剩余 99%、98% 的百分比......同样明智 **
【问题讨论】:
标签: java android android-asynctask progressdialog