3

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

VinZen
  • 313
  • 3
  • 13
  • http://stackoverflow.com/questions/20067508/get-real-path-from-uri-android-kitkat-new-storage-access-framework/20559175#20559175 – VinZen Aug 28 '15 at 09:24
  • And what is your initial path? `String fileName = pPackageBean.getSaveAsName().replaceAll("\\s+", "_").replaceAll("[^a-zA-Z0-9\\_\\-]", ""); `. And what is the value of `fileName? – greenapps Aug 28 '15 at 09:52
  • `don't know where my_downloads come from`. Then you should read a little about content providers. http://developer.android.com/reference/android/content/ContentProvider.html – greenapps Aug 28 '15 at 09:55
  • `fileName` is not a path just a name. – VinZen Aug 31 '15 at 08:41
  • 1
    i resolve the issue by using this: http://stackoverflow.com/questions/20067508/get-real-path-from-uri-android-kitkat-new-storage-access-framework/20559175#20559175 – VinZen Aug 31 '15 at 08:41

0 Answers0