java - 访问 Storage.DIRECTORY_DOWNLOADS(根目录/下载文件夹以查看文件)
问题描述
此方法无法读取下载的文件
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);
...
推荐阅读
- excel - 更改文本框中的字体大小
- python - 在 CSV 文件 Python 之间复制特定行
- kotlin - Coroutines 和 Okhttp 中的取消
- data-visualization - Mlflow 可以在每一步都记录混淆矩阵吗?
- postgresql - 在 Postgres 中也将三列数据连接成一列,其中包含单列值
- php - 闭包类的对象无法在 laravel 中转换为字符串
- python - 如何检测连接图像上元素的角“关节”?
- php - 尝试从 api.facebook.com/restserver.php 获取访问令牌时收到错误消息
- json - Knime JSON 转换器 - 向 JSON 对象添加属性
- active-directory - 使用活动目录验证命令行实用程序