问题
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
?
回答1:
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?
来源:https://stackoverflow.com/questions/27330884/android-4-4-2-not-deleting-files