File imagesFolder = new File( Environment.getExternalStorageDirectory() , "FolderName" );
imagesFolder.mkdirs();
final File image = new File( imagesFolder , "/" + "IMG_" +System.currentTimeMillis() + ".png" );
File file = new File( Environment.getExternalStorageDirectory() + "/" + System.currentTimeMillis() + ".png");
imgCap.takePicture(image, new ImageCapture.OnImageSavedListener() {
@Override
public void onImageSaved(@NonNull File file) {
String msg = "Pic captured at " + image.getAbsolutePath();
//storing the image in a folder in gallery
Intent mediaScanIntent = new Intent( Intent.ACTION_MEDIA_SCANNER_SCAN_FILE );
Uri contentUri = Uri.fromFile( image );
mediaScanIntent.setData( contentUri );
getActivity().sendBroadcast( mediaScanIntent );