Sharing temporary files between applications without an SD card

If I create a temporary file in the application cache directory, I cannot, for example, send it as an attachment. This is because another application does not have permission to read the file.

In API 9 and above, I can set the file to be readable with setReadable (true, false). Unfortunately, I am targeting API level 7+. I donโ€™t want to rely on having an SD card, so I cannot use the location returned by getExternalStorageDir () to save it if there is no card.

How can I generate and share a temporary file in a way that will work even if there is no SD card?

+6
source share
1 answer
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)

+8
source

Source: https://habr.com/ru/post/888607/


All Articles