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);
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();
}
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?
I used android.permission.WRITE_EXTERNAL_STORAGE
in my manifest file.