If I create a temp file in my application's cache directory I can't, for instance, email it as an attachment. This is because the other app doesn't have permission to read the file.
In API 9 and up, I can set the file to be world readable with setReadable(true, false). unfortunately, I am targetting API level 7+. I don't want to rely on the presence of an SD card, so I can't use the location returned by getExternalStorageDir() to store it in case no card is present.
How can I generate and share a temp file in a way that will work, even with no SD card present?
final String FILENAME = "file.tmp";
final String someData = "File data";
FileOutputStream fos = openFileOutput(FILENAME,
Context.MODE_WORLD_WRITEABLE |
Context.MODE_WORLD_READABLE);
fos.write(someData.getBytes());
fos.close();
http://developer.android.com/reference/android/content/Context.html#openFileOutput(java.lang.String,%20int)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With