[英]Generated text file can be found by third party app in Download folder but not shown in Android's default Downloads app
我正在嘗試創建一個下載按鈕,該按鈕將字符串保存在.txt文件和Android的Downloads文件夾中。
現在,可以使用第三方應用程序(例如Android File Transfer
或File Explorer
在Download文件夾中找到此pgn.txt。 但是,我不知道為什么文件沒有顯示在Android的默認應用程序Downloads
。
有人可以幫我嗎? 非常感謝!
這是我的代碼。
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.