[英]Generated text file can be found by third party app in Download folder but not shown in Android's default Downloads app
I'm trying to make a download button, which saves a string in a .txt file and in Android's Downloads folder. 我正在尝试创建一个下载按钮,该按钮将字符串保存在.txt文件和Android的Downloads文件夹中。
Now I can find this pgn.txt in the Download folder using third party apps like Android File Transfer
or File Explorer
. 现在,可以使用第三方应用程序(例如
Android File Transfer
或File Explorer
在Download文件夹中找到此pgn.txt。 However, I don't know why the file is not showing in the Android's default app Downloads
. 但是,我不知道为什么文件没有显示在Android的默认应用程序
Downloads
。
Anyone can help me with this? 有人可以帮我吗? Thanks a lot!
非常感谢!
Here is my code. 这是我的代码。
public void onPositiveButtonClicked(int dialogId, String input) {
String str = "some string"
File downloads = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
try {
File pgnfile = new File(downloads.getAbsolutePath(), "pgn.txt");
FileWriter pgnwriter;
pgnwriter = new FileWriter(pgnfile);
BufferedWriter out = new BufferedWriter(pgnwriter);
out.write(str);
out.flush();
out.close();
MediaScannerConnection.scanFile(getContext(), new String[]{pgnfile.getAbsolutePath()}, null, new OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
}
});
} catch (IOException e) {
e.printStackTrace();
}
// OutputStreamWriter outputStreamWriter = new OutputStreamWriter(getContext().openFileOutput("config.txt", Context.MODE_PRIVATE));
// outputStreamWriter.write(pgn);
// outputStreamWriter.close();
}
“下载”应用程序仅显示通过DownloadManager
文件,而不显示位于DIRECTORY_DOWNLOADS
位置的任意文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.