为什么下载路径与使用DownloadManager的Android M上的初始路径不同?

时间:2015-08-28 09:12:27

标签: android android-download-manager download-manager android-6.0-marshmallow

以下代码适用于Android< 6.0

下载:

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);

处理成功:

case DownloadManager.STATUS_SUCCESSFUL:
long id = packageBean.getDownloadId();
Uri uri =  mDownloadManager.getUriForDownloadedFile(id);
packageBean.path = uri.getEncodedPath();

因此,uri是:content://downloads/my_downloads/867,这是不期望的。867是下载的ID,不知道my_downloads来自哪里。

在4.2.2上我得到:file:///storage/emulated/0/Download/Yvan_Test

0 个答案:

没有答案