此方法无法读取下载的文件
File localFile = new File(Storage.DIRECTORY_DOWNLOADS + downloadableFileName);
这也工作
File localFile = new File(getContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) + downloadableFileName);
文件下载到根目录/下载文件夹而不是应用程序特定文件夹
任何人都可以帮助
下载方法是
protected Void doInBackground(String... strings) {
String fileUrl = strings[0]; // -> http://maven.apache.org/maven-1.x/maven.pdf
String filename = strings[1];
String extStorageDirectory = Storage.DIRECTORY_DOWNLOADS;
File folder = new File(extStorageDirectory);
folder.mkdir();
initClipboardDownloadListener(filename);
Downloader request = Downloader.getInstance(getActivity())
.setListener(downloadListener)
.setUrl(fileUrl)
.setToken(fileUrl)
.setAllowedOverRoaming(true)
.setVisibleInDownloadsUi(true)
.setDescription("Downloading....")
.setKeptAllDownload(true)
.setScanningByMediaScanner(false)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setDestinationDir(extStorageDirectory, filename)
.setNotificationTitle(filename);
request.setAllowedOverMetered(true);
request.start();
return null;
}