The code below works fine for Android < 6.0
Downloading:
DownloadManager.Request request = new DownloadManager.Request(downloadUri);
// Remove all whitespace and more char.
String fileName = pPackageBean.getSaveAsName().replaceAll("\\s+", "_").replaceAll("[^a-zA-Z0-9\\_\\-]", "");
request.setDescription(mContext.getString(R.string.application_name));
request.setTitle(pPackageBean.getSaveAsName());
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
id = mDownloadManager.enqueue(request);
pPackageBean.setDownloadId(id);
Handling success:
case DownloadManager.STATUS_SUCCESSFUL:
long id = packageBean.getDownloadId();
Uri uri = mDownloadManager.getUriForDownloadedFile(id);
packageBean.path = uri.getEncodedPath();
As result the uri is: content://downloads/my_downloads/867
which is not expected.867
is the download's id and don't know where my_downloads
come from.
On 4.2.2 i get : file:///storage/emulated/0/Download/Yvan_Test