title: Can't create a directory in external sd card (Lollipop)
body: <p>I have no problem with internal storage but I want to create a directory on the external SD card, with versions prior to KitKat, <code>File.mkdirs()</code> works.</p>
  
  <p>There is part of my code:</p>
  
  <pre><code>//external sd card
  DocumentFile.fromFile(new File("/storage/sdcard1/")).exists(); //returns true
  DocumentFile.fromFile(new File("/storage/sdcard1/")).canRead(); //returns true
  DocumentFile.fromFile(new File("/storage/sdcard1/")).canWrite(); //returns true
  DocumentFile.fromFile(new File("/storage/sdcard1/test")).exists(); //returns false
  DocumentFile.fromFile(new File("/storage/sdcard1/")).createDirectory("test"); //returns null
  
  //internal storage
  DocumentFile.fromFile(new File("/storage/emulated/0/")).exists(); //returns true
  DocumentFile.fromFile(new File("/storage/emulated/0/test")).exists(); //returns false
  DocumentFile.fromFile(new File("/storage/emulated/0/")).createDirectory("test"); //it works
  DocumentFile.fromFile(new File("/storage/emulated/0/test")).exists(); //returns true
  DocumentFile.fromFile(new File("/storage/emulated/0/test")).createFile("text", "file.txt"); //it works
  
  //external sd card
  (new File("/storage/sdcard1/test2/subfolder")).exists(); //returns false
  (new File("/storage/sdcard1/test2/subfolder")).mkdirs(); //returns false
  
  //internal storage
  (new File("/storage/emulated/0/test2/subfolder")).exists(); //returns false
  (new File("/storage/emulated/0/test2/subfolder")).mkdirs(); //returns true
  </code></pre>
  
  <p>In AndroidManifest.xml:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>Testing with an BQ Aquaris e4, Android Lollipop 5.0 and a 1GB micro SD card.</p>
  
  <p>UPDATE: This is how I get the volume list:</p>
  
  <pre><code>private static ArrayList&lt;StorageInfo&gt; listAvaliableStorage(Context context) {
          ArrayList&lt;StorageInfo&gt; storagges = new ArrayList&lt;&gt;();
          StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
          try {
              Class&lt;?&gt;[] paramClasses = {};
              Method getVolumeList = StorageManager.class.getMethod("getVolumeList", paramClasses);
              getVolumeList.setAccessible(true);
              Object[] params = {};
              Object[] invokes = (Object[]) getVolumeList.invoke(storageManager, params);
              if (invokes != null) {
                  StorageInfo info;
                  for (Object obj : invokes) {
                      Method getPath = obj.getClass().getMethod("getPath");
                      String path = (String) getPath.invoke(obj);
                      info = new StorageInfo(path);
                      File file = new File(info.getPath());
                      if ((file.exists()) &amp;&amp; (file.isDirectory())
                          //&amp;&amp; (file.canWrite())
                              ) {
                          info.setTotalStorage(file.getTotalSpace());
                          info.setFreeStorage(file.getUsableSpace());
                          Method isRemovable = obj.getClass().getMethod("isRemovable");
                          String state;
                          try {
                              Method getVolumeState = StorageManager.class.getMethod("getVolumeState", String.class);
                              state = (String) getVolumeState.invoke(storageManager, info.getPath());
                              info.setState(state);
                              info.setRemovable((Boolean) isRemovable.invoke(obj));
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
  
                          storagges.add(info);
                      }
                  }
              }
          } catch (NoSuchMethodException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
              e.printStackTrace();
          }
          storagges.trimToSize();
  
          return storagges;
      }
  </code></pre>
  
  <p>The hard coded paths is only for this example</p>
  
  <p>UPDATE 2:
  I've created the directory: "test" in SD Card with a file explorer. When I execute this code:</p>
  
  <pre><code>File file = new File("/storage/sdcard1/test/", "file.txt");
  fileOutput = new FileOutputStream(file);
  </code></pre>
  
  <p>The second line throws <code>FileNotFoundException: /storage/sdcard1/test/file.txt: open failed: EACCES (Permission denied)</code></p>
  
  <p>What am I doing wrong?</p>