title: Android - Unable to save images
body: <p>I'm currently trying to get image saving to happen using the device built in camera. This is the code I'm using:</p>
  
  <pre><code>            PackageManager pm = getActivity().getPackageManager();
              if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
                  Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  
                  // * Ensure that there's a camera activity to handle the intent
                  if (takePictureIntent.resolveActivity(pm) != null) {
                      // * Create the File where the photo should go
                      File photoFile = null;
                      try {
                          photoFile = ImageFileHelper.createImageFile();
                      } catch (IOException ex) {
                          // * Error occurred while creating the File
                          Timber.d("An error occurred while creating file: " + ex.getLocalizedMessage());
                      }
                      // * Continue only if the File was successfully created
                      if (photoFile != null) {
                          takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                          startActivityForResult(takePictureIntent, REQUEST_CODE_TAKE_PICTURE);
                      } else {
                          alertUserOfError(0);
                      }
                  }
              } else {
                  // * Inform user that they need a camera 
                  // * to use this feature
                  alertUserOfError(1);
              }
  </code></pre>
  
  <p>And here is the ImageFileHelper.createImageFile() function:</p>
  
  <pre><code>public static File createImageFile() throws IOException {
  
      // Create an image file name
      String timeStamp = new SimpleDateFormat("yyyy-MM-dd.ss", Locale.getDefault()).format(new Date());
      String imageFileName = "Original_Avatar_" + timeStamp;
  
      // * Create MyApp folder if not exist
      String path = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_PICTURES;
      File dir = new File(path + "/MyApp/Originals/");
      dir.mkdirs();
  
      File image = File.createTempFile(
          imageFileName,      /* prefix */
          ".png",             /* suffix */
          dir                 /* directory */
      );
  
      // Save a file: path for use with ACTION_VIEW intents
      filePath = "file:" + image.getAbsolutePath();
      Timber.d("image created at: " + filePath);
      return image;
  }
  </code></pre>
  
  <p>My permissions &amp; features:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
  &lt;uses-feature android:name="android.hardware.camera" android:required="false" /&gt;
  &lt;uses-feature android:glEsVersion="0x00020000" android:required="true"/&gt;
  </code></pre>
  
  <p>This seems to work just fine on my test devices and the majority of my beta tester devices. However, there is one guy who reports that he gets an error message generated by alertUserOfError(0) (you'll see that in the above code), essentially that the photoFile is null.</p>
  
  <p>He is using a rooted HTC One (M8) (htc_m8). Could this be an issue due to the device being rooted?</p>
  
  <p>Any help is appreciated.</p>
  
  <p><strong>UPDATE 2015-05-30</strong>
  I haven't had a chance to add reporting to the catch statement yet, but I did add a method to test for valid paths/directories. Here is how it works:</p>
  
  <pre><code>    StringBuilder build = new StringBuilder();
  
      String path_1 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "MyApp" + File.separator + "Cropped" + File.separator;
      File dir_1 = new File(path_1);
  
      dir_1.mkdirs();
      if (dir_1.exists()) {
          build.append("path 1 valid, ");
      } else {
          build.append("path 1 invalid, ");
      }
  </code></pre>
  
  <p>Using this same setup I also tested the following dirs:</p>
  
  <pre><code>Environment.getExternalStorageDirectory() + File.separator + "MyApp" + File.separator + "Cropped" + File.separator;
  Environment.getDataDirectory() + File.separator + "MyApp" + File.separator + "Cropped" + File.separator;
  </code></pre>
  
  <p>The StringBuilder.toString() is then used as the message in an alert for the tester to send the results back to us.</p>
  
  <p>The above resulted in all paths being invalid:
  path_1 invalid, path_2 invalid, path_3 invalid </p>
  
  <p>So does this mean that those directories just don't exist on the HTC One (M8) (htc_m8) and cannot be created?</p>