Damir
Damir

Reputation: 56179

How to save image captured with camera in specific folder

I am trying to save photo and video like

Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String pathMedia = Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyImages/image_001.png";
Uri uriSavedImage = Uri.fromFile(new File(pathMedia));
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);

but it doesn't work ( I pass through onResult and everything is Ok ) but there is no folder MyImages. How to force phone to save images to specific folder ( it needs to work on every model phone with Froyo or upper) ? I added to manifest WRITE_EXTERNAL STORAGE and CAMERA privileges.

Upvotes: 4

Views: 17009

Answers (1)

dmon
dmon

Reputation: 30168

It's probably because you never created the folder, try this:

File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MyImages");
imagesFolder.mkdirs(); // <----
File image = new File(imagesFolder, "image_001.jpg");
Uri uriSavedImage = Uri.fromFile(image);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);

Upvotes: 11

Related Questions