gpt4 book ai didi

java - 访问 Storage.DIRECTORY_DOWNLOADS(根/下载文件夹以查看文件)

转载 作者:行者123 更新时间:2023-12-01 16:27:17 25 4
gpt4 key购买 nike

此方法无法读取下载的文件

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

关于java - 访问 Storage.DIRECTORY_DOWNLOADS(根/下载文件夹以查看文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62126913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com