I've seen a lot of posts here that say that this is solved, but watching at the dates, I think the most recent I've seen is from 2015. I've tried what I found and couldn't solve it.
Mainly, what I've tried was to find the file (in different ways) from the uri, but it says it doesn't exists.
Also I've found this:
getContentResolver().delete(data.getData, null, null)
called inside the onActivityResult(int requestCode, int resultCode, Intent data) method, after I've taken the picture from the camera. In this case I got a NPE because data comes as null.
EDIT
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_open_camera) {
ContentValues values = new ContentValues();
imageName = "Example" + System.currentTimeMillis();
values.put(MediaStore.Images.Media.TITLE, imageName);
values.put(MediaStore.Images.Media.DESCRPITION, "Camera_" + System.currentTimeMillis());
imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, imageName);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageuri);
if (takePictureIntent.resolveActivity(this.getPackageManager()) != null) {
startActivityForResult(takePictureIntent, 1);
}
return true;
}
return super.onOptionsItemSelected(item);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && resultCode == RESULT.OK) {
Bitmap image = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
// I do some stuff with this image here and want to delete it afterwards
File fDelete = new File(imageUri.getPath());
getApplicationContext().deleteFile(fDelete.getName());
}
}