I have to make some changes to one of my apps to support Android 7. I'm creating an ACTION_IMAGE_CAPTURE - Intent with a content Uri for EXTRA_OUTPUT, and I want to set the filename that is used for the image. Is there a way to do this by setting a certain entry for ContentValues ? The Uri I get from back from
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
contains the MediaStore ID of the file. I look up the real image path at a later point, but I want to define the filename before the Intent is processed.
Code for creating the intent:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues(3);
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
docUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, docUri);
startActivityForResult(takePictureIntent, PICK_PHOTO_CODE);
UPDATE: Final code, with setting the filename and date taken of the photo:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues(3);
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
values.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
values.put(MediaStore.Images.Media.DATE_TAKEN, new Date().getTime());
docUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, docUri);
startActivityForResult(takePictureIntent, PICK_PHOTO_CODE);