Home Ask Login Register

Developers Planet

Your answer is one click away!

JoyceJi February 2016

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.

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();
            }

Answers


CommonsWare February 2016

The Downloads app only shows files downloaded via DownloadManager, not arbitrary files placed in the DIRECTORY_DOWNLOADS location.

Post Status

Asked in February 2016
Viewed 1,754 times
Voted 5
Answered 1 times

Search




Leave an answer


Quote of the day: live life