title: Android failed to mkdir() on SD card
body: <p>I have some code to create/get a folder on SD card:</p>
  
  <pre><code>if( hasSDCard() ){
  
          UUID uniqueFileName = UUID.randomUUID();
  
          mediaStorageDir = new File(
                  getExternalImageStoragePath(),
                  "MyApp");
  
          if ( ! mediaStorageDir.exists() ){
  
              if( ! mediaStorageDir.mkdirs() ){
  
                  MyLogger.Error("Create image directory FAILED. path: " + mediaStorageDir.getPath());
  
                  return null;
              }
          }
  </code></pre>
  
  <p>and I have the permission registered in my Manifest file:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STOREAGE"/&gt;
  &lt;uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/&gt;
  </code></pre>
  
  <p>but when I run it, it prints:</p>
  
  <pre><code>Create image directory FAILED. path: /storage/emulated/0/Pictures/MyApp
  </code></pre>
  
  <p>I was wondering why this happens?</p>
  
  <p>=== UPDATE ===</p>
  
  <p>I have tried all of them: </p>
  
  <pre><code>/**
   * get external storage directory path for image
   * @return
   */
  public static String getExternalImageStoragePath(){
  
      String strPath = "";
  
      if(hasSDCard()){
          //strPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath();
          //strPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath();
          //strPath = Environment.getExternalStorageDirectory().getPath();
          strPath = Environment.getExternalStorageDirectory().getAbsolutePath();
      }
  
      return strPath;
  }
  </code></pre>
  
  <p>But they all behave exactly the same...</p>
  
  <p>=== UPDATE 2 ===</p>
  
  <p>I am testing with Nexus 5. I saw this post <a href="https://stackoverflow.com/questions/15641848/cannot-find-storage-emulated-0-folder-of-nexus-7-in-eclipse">Cannot find storage/emulated/0/ folder of Nexus 7 in Eclipse</a>  There might be some issue?</p>
  
  <p>=== UPDATE 3 ===</p>
  
  <pre><code>&gt;&gt; adb shell ls -l /storage/
  dr-xr-xr-x root     root              1970-01-24 23:48 emulated
  lrwxrwxrwx root     root              1970-01-24 23:48 sdcard0 -&gt; /storage/emulated/legacy
  
  &gt;&gt; adb shell ls -l /storage/emulated/0/Pictures/
  /storage/emulated/0/Pictures/: No such file or directory
  </code></pre>
  
  <p>=== UPDATE 4 ===</p>
  
  <p>Here is my <code>hasSD()</code> method:</p>
  
  <pre><code>public static boolean hasSDCard(){
      boolean fHasSDCard = false;
  
      if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
          fHasSDCard = true;
      }
  
      return fHasSDCard;
  }
  </code></pre>