文件下载提交

This commit is contained in:
frank wang 2025-10-15 14:56:00 +08:00
parent 14f462050c
commit b27394526c
1 changed files with 4 additions and 6 deletions

View File

@ -276,7 +276,6 @@ public class FirstActivity extends BaseActivity {
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
if (dm != null) { if (dm != null) {
currentDownloadId = dm.enqueue(request); currentDownloadId = dm.enqueue(request);
Toast.makeText(this, "文件已开始下载,请等待" + currentDownloadId, Toast.LENGTH_SHORT).show();
startDownloadProgressMonitor(dm, currentDownloadId); startDownloadProgressMonitor(dm, currentDownloadId);
} else { } else {
Toast.makeText(this, "系统下载服务不可用", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "系统下载服务不可用", Toast.LENGTH_SHORT).show();
@ -299,24 +298,23 @@ public class FirstActivity extends BaseActivity {
while (downloading) { while (downloading) {
try { try {
Toast.makeText(this, "文件已开始下载,请等待", Toast.LENGTH_SHORT).show();
Thread.sleep(1000); Thread.sleep(1000);
android.database.Cursor cursor = dm.query(query); android.database.Cursor cursor = dm.query(query);
Toast.makeText(this, "文件已开始下载,请等待" + cursor, Toast.LENGTH_SHORT).show();
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)); int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
long total = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); long total = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
long downloaded = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); long downloaded = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
Toast.makeText(this, "文件已开始下载,请等待" + status + "," + total + "," + downloaded, Toast.LENGTH_SHORT).show();
if (status == DownloadManager.STATUS_RUNNING && total > 0) { if (status == DownloadManager.STATUS_RUNNING && total > 0) {
int progress = (int) ((downloaded * 100L) / total); int progress = (int) ((downloaded * 100L) / total);
Toast.makeText(this, "1.文件已开始下载部分进度调用前端js" + status + "," + total + "," + downloaded, Toast.LENGTH_SHORT).show(); Toast.makeText(this, "下载中,当前进度为" + progress + "%", Toast.LENGTH_SHORT).show();
handler.post(() -> sendProgressToJs(progress)); handler.post(() -> sendProgressToJs(progress));
} else if (status == DownloadManager.STATUS_SUCCESSFUL) { } else if (status == DownloadManager.STATUS_SUCCESSFUL) {
Toast.makeText(this, "2.文件已开始下载进度成功调用前端js" + status + "," + total + "," + downloaded, Toast.LENGTH_SHORT).show(); Toast.makeText(this, "下载完成,请到文件管理查看", Toast.LENGTH_SHORT).show();
downloading = false; downloading = false;
handler.post(() -> sendProgressToJs(100)); handler.post(() -> sendProgressToJs(100));
} else if (status == DownloadManager.STATUS_FAILED) { } else if (status == DownloadManager.STATUS_FAILED) {
Toast.makeText(this, "3.文件已开始下载,进度失败调用前端js" + status + "," + total + "," + downloaded, Toast.LENGTH_SHORT).show(); Toast.makeText(this, "下载失败" + status + "," + total + "," + downloaded, Toast.LENGTH_SHORT).show();
downloading = false; downloading = false;
handler.post(() -> sendProgressToJs(-1)); handler.post(() -> sendProgressToJs(-1));
} }