【发布时间】:2019-02-20 21:31:11
【问题描述】:
我使用 WebView 启用了文件的下载设置。我正在使用 DownloadManager 保存文件。但是这些文件不会出现在本地下载目录中。我下载的文件都保存在这里。
> file/storage/emulated/0/Android/data/com.myapp/files/x.mp3
我已经尝试了很多。但不知何故,它没有下载到本地下载文件夹中。我该怎么办?
我的代码
String string = String.valueOf((URLUtil.guessFileName(url, contentDisposition, mimeType)));
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setTitle("test17");
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalFilesDir(getContext(), DIRECTORY_DOWNLOADS , string);
DownloadManager dm = (DownloadManager)getActivity().getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
【问题讨论】:
-
使用Prdownloader库..易于使用和集成
标签: android android-studio android-download-manager