【发布时间】:2017-08-12 14:09:53
【问题描述】:
我使用 android 下载管理器编写了一个 android 应用程序,并尝试使用以下代码显示下载进度。
myTimer.schedule(new TimerTask() {
public void run() {
try {
DownloadManager.Query q;
q = new DownloadManager.Query();
q.setFilterById(preferenceManager.getLong(strPref_Download_ID, 0));
cursorTimer = downloadManager.query(q);
cursorTimer.moveToFirst();
int bytes_downloaded = cursorTimer.getInt(cursorTimer.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
bytes_total = cursorTimer.getInt(cursorTimer.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
final int dl_progress = (int) ((double) bytes_downloaded * 100f / (double) bytes_total);
mProgressDialog.setProgress((int) dl_progress);
} catch (Exception e) {
} finally {
}
}
}, 0, 10);
一切正常,但进度对话框没有显示平滑的 pregress,这意味着我希望显示 1、2、3、4、5、6、.....100。
它最初显示为 0,然后突然变为 12%,然后是 31%,等等 100%。 我的文件总大小是 26246026 字节,在 0% 时我下载的文件大小是 6668 字节, 在 12% 时,我下载的文件大小为 3197660 字节,等等......
【问题讨论】:
标签: android progressdialog android-download-manager