[英]Access Storage.DIRECTORY_DOWNLOADS (Root/Download Folder To View a file)
此方法無法讀取下載的文件
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;
}
嘗試這個:
...
String path = Environment.getExternalStorageDirectory().toString() +"/Download/" + fileName;
File file = new File(path);
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.