Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save image captured with camera in specific folder

Tags:

android

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.

like image 510
Damir Avatar asked Dec 21 '22 05:12

Damir


1 Answers

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);
like image 142
dmon Avatar answered May 18 '23 19:05

dmon