简体   繁体   English

Android 4.4.2不删除文件

[英]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 . 当我调试此代码时,它对isDeleted每个文件都说是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 ? 任何人都知道为什么不删除文件,即使它说isDeletedtrue

You can't delete files anymore in Android 4.4.2. 您无法再在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. 您需要做的是根除手机,然后安装诸如SDFix之类的应用程序。 That you way you gain full access to your SD Card again. 这样,您就可以再次完全访问SD卡。

That's currently the best way. 这是目前最好的方法。

Or you could try a "loophole", as in this post: 或者您可以尝试“漏洞”,如本文所示:

How to delete a file from SD card? 如何从SD卡删除文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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