删除Android上的SD卡文件 [英] Delete file on Android SD card
问题描述
在我的应用程序可以拍摄照片和与此code保存:
In my application I can take a photo and save it with this code:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageCaptureUri = Uri.fromFile(new File(context.getExternalFilesDir(null),
"tmp_image_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageCaptureUri);
intent.putExtra("return-data", true);
我想从我的SD卡与此code删除文件:
I tried to delete the file from my SD card with this code:
File f = new File(imageCaptureUri.getPath());
if (f.exists() == true)
{
boolean state = f.delete();
Toast.makeText(context, "" + state, Toast.LENGTH_LONG).show();
}
在吐司
的输出是真实的,但该文件未在SD卡上删除。我测试了Android KitKat上,但它应该工作在较旧的Android版本过多。你有我为什么不能删除照片什么想法?
The output of the Toast
is true but the file is not deleted on the SD card. I tested this on Android KitKat but it should work on older android versions too. Do you have any ideas why I can't delete the photo?
我用 android.permission.WRITE_EXTERNAL_STORAGE
在我的清单文件。
推荐答案
奇巧对如何应用程序可以与否访问文件的一些变化。甚至在外部存储
KitKat have some changes on how apps can or not access files. Even in the external storage.
由于这是一个临时文件,我建议你把它迁移到你自己的应用空间,比如 context.getCacheDir
来代替。这可能会奏效。
Because that's a temp file, I suggest you to relocate it to your own app space like context.getCacheDir
instead. That will probably work.
这篇关于删除Android上的SD卡文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!