I'm trying to make a download button, which saves a string in a .txt file and in Android's Downloads folder.
Now I can find this pgn.txt in the Download folder using third party apps like Android File Transfer
or File Explorer
. However, I don't know why the file is not showing in the Android's default app 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
位置的任意文件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.