I'm using Android download manager for my application and it works perfectly. But I need to get downloading file name when it's stored. I didn't get the file name and it get's an error. I have tried all previous solutions as well. Please help me to fix this.
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();