If I create a temp file in my application's cache di开发者_如何学运维rectory 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)
精彩评论