title: Can an Android app obtain write permission to /mnt/asec or /mnt/obb?
body: <p>I have an application that performs a write operation on an external SD Card (external as in not the "external" in the device's flash memory), but as it has been thoroughly discussed <a href="https://stackoverflow.com/questions/5694933/find-an-external-sd-card-location">here</a> and in quite a few other questions, it appears there is no generic way / supported API to retrieve an SD Card mounting point that works on every phone, from different manufacturers.</p>
  
  <p>With that in mind, something like the code below needs to be done to find out if an external storage device is mounted and where:</p>
  
  <pre><code>final String state = Environment.getExternalStorageState();
  
  if ( Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) ) {  // we can read the External Storage...           
      //Retrieve the primary External Storage:
      final File primaryExternalStorage = Environment.getExternalStorageDirectory();
  
      //Retrieve the External Storages' root directory:
      final String externalStorageRootDir;
      if ( (externalStorageRootDir = primaryExternalStorage.getParent()) == null ) {  // no parent...
          Log.i("SD Card Path", "External Storage: " + primaryExternalStorage + "\n");
      }
      else {
          final File externalStorageRoot = new File( externalStorageRootDir );
          final File[] files = externalStorageRoot.listFiles();
  
          for ( final File file : files ) {
              if ( file.isDirectory() &amp;&amp; file.canRead() &amp;&amp; (file.listFiles().length &gt; 0) ) {  // it is a real directory (not a USB drive)...
                  Log.i("SD Card Path", "External Storage: " + file.getAbsolutePath() + "\n");
              }
          }
      }
  }
  </code></pre>
  
  <p>I could be wrong, but I understand the SD Card could be completely empty and that last condition <code>(file.listFiles().length &gt; 0)</code> could return <code>false</code>. So I thought, instead of checking that <code>length</code>, I would add <code>file.canWrite()</code>. That worked as I expected on the phone I am currently testing on (Motorola Atrix MB860 - it's old, I know, but one of my requirements is make it compatible with versions starting from Gingerbread, API 9), but I am unsure whether or not that condition could return true to <code>/mnt/asec/</code> or <code>/mnt/obb</code> on other phones , recent or not, since their both readable directories, thus also satisfying the first two conditions (and could even return <code>true</code> to <code>(file.listFiles().length &gt; 0)</code> if it had something written on it (like a 50MB+ size file on <code>/mnt/obb</code>).</p>
  
  <p>So, in short, what I need to know is whether an app will ever have write permission to these two locations or if only the system has such permission. If yes, what else can I check for in order to exclude them from the final path I wish to obtain: the external SD Card installed on the device?</p>
  
  <p>Thank you in advance for any help!</p>