gpt4 book ai didi

android - DownloadManager 下载完成但文件未存储

转载 作者:行者123 更新时间:2023-12-04 23:41:58 26 4
gpt4 key购买 nike

我遇到了 DownloadManager 的奇怪问题, 下载成功但文件未存储。

所以这是我的代码:

try {
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
request.setDestinationInExternalFilesDir(context, /temp/, "test.mp4");
final long downloadId = manager.enqueue(request);
boolean downloading = true;
while (downloading) {
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(downloadId);
Cursor cursor = manager.query(query);
cursor.moveToFirst();
int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
int bytesDownloaded = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
int bytesTotal = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
if(status==DownloadManager.STATUS_SUCCESSFUL){
Log.i("Progress", "success");
downloading = false;
}
final int progress = (int) ((bytesDownloaded * 100l) / bytesTotal);
cursor.close();
subscriber.onNext(progress);
}
subscriber.onCompleted();
}catch (Exception e){
subscriber.onError(e);
}

我已包含 WRITE_EXTERNAL_STORAGE在我的 list 上。我尝试将目录更改为 Environment.DIRECTORY_DOWNLOADS但文件仍未存储到下载目录。我试图在 /Android/data/<my package>/ 上找到它并且下载的文件也不在那里。那么我的代码有什么问题?

额外的:
在日志中显示我的下载已完成。

enter image description here

最佳答案

我也有这个问题,但是换了之后就解决了

    request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, videoName+".mp4");


request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS.toString(), videoName+".mp4");

现在它保存在“下载”文件夹中。

关于android - DownloadManager 下载完成但文件未存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35652846/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com