Jona
Jona

Reputation: 13555

Something is deleting image files from getExternalFilesDir()?

I'm having a hard time figuring out what is going on with my app. Various users have reported that the app generated image files are gone. However, the database data isn't gone and it is stored at the common location Context.getDatabasePath(). Also, all folders are kept intact just images missing.

So I'm thinking there is some routine in Android causing this? Or some other app cleaning up *.png files? I know my app isn't removing them since I don't have any routine to recursively remove all image files.

Also, the parent folder has the .nomedia file so all child folders shouldn't be touched by the gallery right?

I'm storing these files inside the following path structure where %d is a unique number:

getExternalFilesDir()/projects/p_%d/l_%d/%d.png

This is how I get the projects path creates:

public static File getProjectsDir(Context context)
{
    // External app directory handled by the OS. Meaning that when the app is uninstalled all
    // the data inside this folder will be also removed.
    File appRoot = context.getExternalFilesDir(null);
    if (null == appRoot) {
        Log.e(TAG,"getProjectsDir() -> External storage not accessible!");
        return null;
    }

    File projectsDir = new File(appRoot, "projects");

    // create projects directory
    if (!projectsDir.exists()) {
        if (!projectsDir.mkdir()) {
            Log.e(TAG,"getProjectsDir() -> Unable to create projects folder!");
            return null;
        } else {
            File noMediaFile = new File(projectsDir, ".nomedia");
            if (!noMediaFile.exists()) {
                try {
                    if (!noMediaFile.createNewFile()) {
                        Log.e(TAG,"getProjectsDir() -> no media file failed to be created!");
                    }
                } catch (IOException e) {
                    Log.e(TAG,"getProjectsDir() -> no media file failed to be created!",e);
                }
            }
        }
    }

    return projectsDir;
}

Upvotes: 2

Views: 427

Answers (1)

Ivan
Ivan

Reputation: 705

According to this, it appears that the DownloadManager deletes any files from third-party apps that haven't been accessed (i.e. "UI-Visible") in over 7 days.

The workaround would be to rename the file after it's downloaded so the DownloadManager can no longer track it.

Upvotes: 1

Related Questions