我遇到了一个与
我在清单文件中包含了
另外,日志显示我的下载已完成。
请参考以下截图:
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
权限。我尝试将目录更改为Environment.DIRECTORY_DOWNLOADS
,但文件仍未存储到下载目录中。我尝试在/Android/data/<my package>/
中查找它,但下载的文件也不在那里。那么我的代码有什么问题呢?另外,日志显示我的下载已完成。
请参考以下截图:
![enter image description here](https://istack.dev59.com/Rm207.webp)
/temp/
。你有检查过那里吗? - Rohit5k2