简体   繁体   中英

Android 4.4.2 not deleting files

I have a peice of code that scans for all files in a directory and it should delete those files. But for some reason it's not deleting them.

What I have is this:

String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/Images/"; 
File f = new File(path);
File file[] = f.listFiles();
for (File aFile : file) {
    boolean isDeleted = aFile.delete();
    if(isDeleted) {
        log.d("file", "is deleted");
    }
}

When I debug this code then it says for every file that isDeleted is true . But when I check the "Gallery/Images" folder on my phone I see that all images are still there...

I also have the following two permission in my manifest:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Anyone any idea why the files aren't deleted, eventhough it says isDeleted is true ?

You can't delete files anymore in Android 4.4.2. At least, not files that were created by other apps. This is a new (and dumb) restriction.

What you have to do is Root your phone and then install an app like SDFix or something similar. That you way you gain full access to your SD Card again.

That's currently the best way.

Or you could try a "loophole", as in this post:

How to delete a file from SD card?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM