TemporaryFile on Android


#1

I need to write some data to a temporary file on Android, but trying to write to a newly created TemporaryFile object I get an assert:

    if (temporaryFile.exists())
    {
        // Have a few attempts at overwriting the file before giving up..
        for (int i = 5; --i >= 0;)
        {
            if (temporaryFile.moveFileTo (targetFile))
                return true;

            Thread::sleep (100);
        }
    }
    else
    {
        // There's no temporary file to use. If your write failed, you should
        // probably check, and not bother calling this method.
        jassertfalse;
    }

Has anyone had any sucess with this class on Android? The same code works fine for me on my PC.


#2

I haven't tried, but I assume you're requesting the required permissions etc..?


#3

Thanks, I'm relatively new to this Android stuff but I do have "android.permission.WRITE_EXTERNAL_STORAGE" set in my AndroidManifest.xml file. Am I missing something else?


#4

Never needed to do that, but found this: http://stackoverflow.com/questions/12317934/what-is-the-best-way-to-create-temporary-files-on-android


#5

Thanks, but I'd rather do this directly within my C++ code rather than use the Java File class. I've a few other things to try out. I'll report back if I get it working. 


#6

Adding permissions for writing to external storage and then creating my file in "/sdcard/" seems to have done the trick. Nice one. I didn't have to go messing with any JAVA stuff whatsoever ;)