最佳答案
我在4.4.2上,试图通过 uri 删除一个文件(图片)。以下是我的代码:
File file = new File(uri.getPath());
boolean deleted = file.delete();
if(!deleted){
boolean deleted2 = file.getCanonicalFile().delete();
if(!deleted2){
boolean deleted3 = getApplicationContext().deleteFile(file.getName());
}
}
现在,这些 delete 函数都没有真正删除文件:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />