Reputation: 31
When you attach a file to an e-mail using the ACTION_SEND intent (with the extra EXTRA_STREAM) does the e-mail app copy that attached file to its own location? My app creates a file and attaches it to an email, but this can happen many times and I would like to be able to delete this file when it is no longer needed (so it doesn't flood the user's storage with junk data). Is the file safe to delete after the e-mail intent has started?
Upvotes: 3
Views: 1368
Reputation: 515
In order to always make a cleanup of the user's storage (SDCard), you can check the lastModified() date of the file for a givend age and delete it.
For example:
private void checkTempFiles() {
Log.d(TAG, "--> checkTempFiles");
// Check if directory 'YourTempDirectory' exists and delete all files
String tempDirectoryPath = Environment.getExternalStorageDirectory()
.toString() + "/YourTempDirectory";
File dir = new File(tempDirectoryPath);
// Delete all existing files older than 24 hours
if (dir.exists() && dir.isDirectory()) {
String[] fileToBeDeleted = dir.list();
for (int i = 0; i < fileToBeDeleted.length; i++) {
File deleteFile = new File(tempDirectoryPath + "/"
+ fileToBeDeleted[i]);
Long lastmodified = deleteFile.lastModified();
if (lastmodified + 86400000L < System.currentTimeMillis()) {
if (deleteFile.isFile()) {
deleteFile.delete();
}
}
}
}
}
Upvotes: 2
Reputation: 6247
No, it's not safe. If you only haven't saved it to Media Library.
Upvotes: 0