title: Android Studio SD Card erroneously reports being empty to my app
body: <p>After going through the headache of figuring out how to make a large SD card (~32gb) using mksdcard and pushing information to it (slowly) using ADB, I can go on to my AVD manager, start up my Nexus 4 (with all default settings), and go to </p>
  
  <p>Settings > Device > Storage &amp; USB > Portable Storage > SDCARD</p>
  
  <p>I see all of the files I expect to see there (i.e. all the default stuff plus everything I pushed).</p>
  
  <p>However, in my app, it tells me there's nothing there. I have a menu item that calls this simple function, but its results are baffling.</p>
  
  <pre><code>public void dumpSDCardContents(MenuItem m) {
      if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
          recursFiles(Environment.getExternalStorageDirectory());
      }
  }
  
  private void recursFiles(File dir){
      System.out.println("Now scanning " + dir.getAbsolutePath());
      File[] listFiles = dir.listFiles();
      if(listFiles != null){
          for(File file : listFiles){
              System.out.println(file.getAbsolutePath());
              if(file.isDirectory()){
                  recursFiles(file);
              }
          }
      } else {
          System.out.println("That directory has nothing in it.");
      }
  }
  </code></pre>
  
  <p>All I see in logcat is</p>
  
  <pre><code>Now scanning /storage/19E8-1D10
  That directory has nothing in it.
  </code></pre>
  
  <p>Which is bollocks. If I go to the File Explorer tab in DDMS, I can see the web of linking from <code>/mnt/sdcard/</code> to <code>/sdcard/</code> to <code>/storage/self/primary/</code> to <code>/mnt/user/0/primary/</code> to (finally) <code>/storage/19E8-1D10/</code> and then looking in that directory, plain as day, is all the data I'm looking for.</p>
  
  <p>I was sure to add </p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>to my AndroidManifest.xml, and besides,  the javadoc comment on <code>Environment.MEDIA_MOUNTED</code> (which I already successfully tested against) says "Storage state if the media is present and mounted at its mount point with read/write access."</p>
  
  <p>What am I missing here???</p>
  
  <p>-</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>So I changed the <code>recursFiles</code> function to dump file permissions</p>
  
  <pre><code>private void recursFiles(File dir){
      System.out.println("Now scanning " + dir.getAbsolutePath());
      System.out.println("Can r dir? " + dir.canRead());
      System.out.println("Can w dir? " + dir.canWrite());
      System.out.println("Can x dir? " + dir.canExecute());
      File[] listFiles = dir.listFiles();
      if(listFiles != null){
          for(File file : listFiles){
              System.out.println(file.getAbsolutePath());
              if(file.isDirectory()){
                  recursFiles(file);
              }
          }
      } else {
          System.out.println("That directory has nothing in it.");
      }
  }
  </code></pre>
  
  <p>and (not terribly surprisingly given the original output) it tells me</p>
  
  <pre><code>Now scanning /storage/17F2-2913
  Can r dir? false
  Can w dir? false
  Can x dir? true
  That directory has nothing in it.
  </code></pre>
  
  <p>So. Why would the <code>Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)</code> check come back true (implying I have both read and write) when I in fact have neither read nor write permissions??</p>
  
  <p>And how do I fix this?</p>
  
  <p>I noticed when I went into the emulator using <code>adb shell</code>, that permissions files (i.e. <code>/system/etc/permissions/platform.xml</code> and <code>/etc/permissions/platform.xml</code>) flat out don't even have a permission tag for <code>WRITE_EXTERNAL_STORAGE</code>.</p>
  
  <p>How do I rectify all this??</p>