Android: save file to downloads that can be viewed later

12,725

Solution 1

Files are not visible unless you make them explicitly available. See my blog post about the MediaScanner to read more about this.

It's the developer's job to take care of this and to make sure that all files, the user might want to access, are made available to the MediaScanner.

Solution 2

I wanted to do a very similar thing. Here's how I got it to work using your code EXACTLY.

After running my code to make the file(/storage/emulated/0/Download/_Ascent_Test.txt):

I downloaded the ES File Explorer.

In the "Fast Access" menu towards the bottom I turned "Show hidden files" ON.

Then, also in the "Fast Access" menu, go to local -> / Device.

Now you will be able to navigate to the /storage folder and all the way down to _Ascent_test.txt

From there you can open it and email it yourself. Hope this helped!

Share:
12,725

Related videos on Youtube

Chuck Finley
Author by

Chuck Finley

Updated on September 15, 2022

Comments

  • Chuck Finley
    Chuck Finley over 1 year

    I have an app that needs to collect a bunch of data while connected to a stream. I need to save this data to a file that I can later pull off my device and analyze using a standard computer.

    My code currently looks like:

    private void saveData(byte[] data){
        File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        File file = new File(path, "_Ascent_Test.txt");        
        try {                      
            FileOutputStream stream = new FileOutputStream(file, true);             
            stream.write(data);            
            stream.close();
            Log.i("saveData", "Data Saved");        
        } catch (IOException e) {
            Log.e("SAVE DATA", "Could not write file " + e.getMessage());
        }       
    }
    

    It's correctly hitting the "Data Saved" log without any errors yet I cannot find the file anywhere in the devices internal storage when I browse it from my computer.

    What am I missing?

    Thanks.

    Edit: I'm needed to run this on a Nexus 7

    • ottel142
      ottel142 about 11 years
      Did you add <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> to your manifest file?
    • Wolfram Rittmeyer
      Wolfram Rittmeyer about 11 years
      You can use adb pull /mnt/shell/emulated/0/Download/_Ascent_Test.txt to get to the file. Or use the file view in DDMS in Eclipse.
  • Patrick Mineault
    Patrick Mineault almost 9 years
    Thanks for that. That was really not obvious.
  • Martin De Simone
    Martin De Simone over 6 years
    You saved me a lot of time, this should be more clear