我正在为我的应用程序使用Android下载管理器,它运行正常。但我需要在存储时下载文件名。我没有得到文件名,这是一个错误。我也尝试过所有以前的解决方案。请帮我解决这个问题。
DownloadManager mgr = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);
boolean isDownloading = false;
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterByStatus(
DownloadManager.STATUS_PAUSED|
DownloadManager.STATUS_PENDING|
DownloadManager.STATUS_RUNNING|
DownloadManager.STATUS_SUCCESSFUL
);
Cursor cur = mgr.query(query);
String filename="";
if (cur.moveToFirst()) {
String filePath = cur.getString(cur.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
filename = filePath.substring( filePath.lastIndexOf('/')+1, filePath.length() );
}
Uri source = Uri.parse(myWebsites[j]);
DownloadManager.Request request = new DownloadManager.Request(source);
request.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
);
request.setDestinationInExternalPublicDir("/MyDownloadManager/"+folderName, filename );
request.allowScanningByMediaScanner();
long id = mgr.enqueue(request);
cur.close();
答案 0 :(得分:0)
如果您通过downloadId
设置过滤器,这可能会正常工作query.setFilterById(id);