Android ACTION_SEND Attached File

When you attach a file to email using the ACTION_SEND intent (with optional EXTRA_STREAM), does the email application copy the attached file to its location? My application creates the file and attaches it to the email, but this can happen many times, and I would like to be able to delete this file when it is no longer needed (therefore it does not fill the user repository with unwanted data). Is file safe to delete after running email intent?

+3
source share
2 answers

To always clear the user repository (SDCard), you can check the lastModified () date of the file for the givend age and delete it.

For instance:

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();
                }
            }
        }
    }
}
+2
source

No, this is not safe. If you have not saved it in the Media Library.

0
source

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


All Articles