开发者

Android ACTION_SEND Attached File

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 o开发者_如何学Cwn 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?


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


No, it's not safe. If you only haven't saved it to Media Library.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜