My application allows users to create and modify files. I would like them to be able to send a file as an email attachment. So, I need to first create and write to a temporary f
You can use Context's getExternalCacheDir() method to get a File reference where you can store files on an SD card. Of course, you'll have to do the usual checks to make sure the external storage is mounted and writable, as usual, but this is probably the best place to store that type of temporary file. One thing you might want to do is just set a maximum amount of space that you can use in the cache directory, and then, any time you need to write a new temporary file, if that file exceeds the maximum space, then start deleting the temp files, starting with the oldest, until there is sufficient space.
EDIT: Alternatively, maybe something like this would work:
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File externalRoot = Environment.getExternalStorageDirectory();
File tempDir = new File(externalRoot, ".myAppTemp");
}
Prepending the "." should make the folder hidden, I'm fairly sure.