Skip to content Skip to sidebar Skip to footer

Android: Asus Nexus 7 Does Not Commit Emulated Memory Until Restart

I have a very specific issue - I am trying to write to external storage on an Asus Nexus 7, but it is writing to the emulated directory on the device. Here is the code I am using:

Solution 1:

I made two methods. One for creating a file and one for appending to it. I think the issue is that you're not calling createNewFile.

privateFileCreateFile(String fileName)
{
    File file = newFile(this.getFilesDir(), fileName);
    try
    {
        if(!file.exists())
        {
            file.createNewFile();
        }
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    return file;
}

privatevoidappendToFile(String file, String content)
{
    try
    {
        OutputStreamWriter outputStreamWriter = newOutputStreamWriter(this.openFileOutput(file, this.MODE_APPEND));
        outputStreamWriter.append(content + "\n");
        outputStreamWriter.close();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}

Solution 2:

Alright after much searching and testing I finally came across a solution, linked via one of the other answers.

https://stackoverflow.com/a/28448843/979220

The solution was to scan the media files, which causes the files to propagate to the external storage, rather than staying in the emulated storage.

Post a Comment for "Android: Asus Nexus 7 Does Not Commit Emulated Memory Until Restart"