From c04469a88160bae9fe1e8b98169a996eba63f83d Mon Sep 17 00:00:00 2001 From: Christophe BOUCAUT Date: Fri, 10 Jul 2015 09:38:58 +0200 Subject: [PATCH] Create the directory for storage the picture in gallery if it doesn't exist. --- .../geneanet/customcamera/CameraActivity.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index 21e7c9e..699b5a7 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -774,14 +774,26 @@ public class CameraActivity extends Activity { // Get path picture to storage. String pathPicture = Environment.getExternalStorageDirectory() .getPath() + "/" + Environment.DIRECTORY_DCIM + "/Camera/"; - pathPicture = pathPicture - + String.format("%d.jpeg", System.currentTimeMillis()); + + // Create the directory if it doesn't exist. + File galleryDirectory = new File(pathPicture); + boolean directoryExist = galleryDirectory.exists(); + if (!directoryExist) { + directoryExist = galleryDirectory.mkdirs(); + } + + if (directoryExist) { + pathPicture = pathPicture + + String.format("%d.jpeg", System.currentTimeMillis()); - // Write data in file. - FileOutputStream outStream = new FileOutputStream(pathPicture); - outStream.write(data); - data = null; - outStream.close(); + // Write data in file. + FileOutputStream outStream = new FileOutputStream(pathPicture); + outStream.write(data); + data = null; + outStream.close(); + } else { + Log.e("customCamera", "The directory for storage the picture in the gallery doesn't exist and his creation is failed."); + } } // Return to success & finish current activity.