Q: Automatically delete files after x days and remove the thumbnail from the madiastore I'm trying to delete pictures that I've created that are older than 3 days (I'm aware I have it set to one second in the code currently) the code works great except the thumbnail in the media store is still present and won't go away until a rescan is triggered but that feature has bee removed and I get a permission denied when I try to add that code. How do I add removal from the media store to this code as well?
DCIMPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString();
        path = DCIMPath + "/Signatures";


        if (savedInstanceState == null) {

            File directory = new File(path);
            if (!directory.exists()) {
                directory.mkdir();
            }

            if (directory.exists()) {
                File[] listFiles = directory.listFiles();
                long purgeTime = System.currentTimeMillis() - (1000);
                for (File listFile : listFiles)
                    if (listFile.lastModified() < purgeTime) {
                        listFile.delete();
                        if (!listFile.delete()) {
                            System.err.println("Unable to delete file: " + listFile);
                        }
                    }
            }
            Toast.makeText(MainActivity.this, "Signatures Older Than 3 Days Deleted", Toast.LENGTH_LONG).show();
        }

