Reputation: 347
public void onPictureTaken(byte[] data, Camera camera)
{
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Raw Image");
imagesFolder.mkdirs();
Date d = new Date();
CharSequence s = DateFormat.format("MM-dd-yy hh-mm-ss", d.getTime());
File output = new File(imagesFolder, s.toString() + ".jpg");
Uri uriSavedImage = Uri.fromFile(output);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
OutputStream imageFileOS;
try {
imageFileOS = getContentResolver().openOutputStream(uriSavedImage);
imageFileOS.write(data);
imageFileOS.flush();
imageFileOS.close();
};
Currently i am creating a folder name "Raw Image" to save the image. What if i want to create more folders in the "Raw Image folder"? Any suggestions please.
Upvotes: 0
Views: 134
Reputation: 6836
you have to check whether the folder is already exist or not. you have to add only one line of code
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Punch");
if (!imagesFolder.exists()) {
imagesFolder.mkdirs();
}
else { //do nothing
}
Upvotes: 1
Reputation: 598
In this way you will create a folder named "another_folder" in the "Raw Image" folder:
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Raw Image/another_folder");
Also you should avoid creating folder/file with blank space in their names
Upvotes: 1
Reputation: 6738
try following code
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Raw Image");
File folder= new File(imagesFolder , "yourfolder name");
folder.mkdirs();
Upvotes: 1