title: Cordova file plugin - save file in device
body: <p>I'm having a lot of troubles saving files in Android.<br>
  The project is a hybrid application developed with Ionic with these plugins:</p>
  
  <pre><code>com.phonegap.plugins.fileopener 1.0.0 "File Opener"
  com.telerik.plugins.nativepagetransitions 0.4.2 "Native Page Transitions"
  cordova-plugin-compat 1.0.0 "Compat"
  cordova-plugin-crosswalk-webview 2.0.0 "Crosswalk WebView Engine"
  cordova-plugin-file 4.2.0 "File"
  cordova-plugin-network-information 1.2.2-dev "Network Information"
  cordova-plugin-whitelist 1.2.3-dev "Whitelist"
  cordova-plugin-wkwebview-engine 1.0.4-dev "Cordova WKWebView Engine"
  ionic-plugin-keyboard 2.2.1 "Keyboard"
  </code></pre>
  
  <p>Android platform version is <code>5.2.1</code><br>
  The device I'm using is a <code>Samsung A7</code>  </p>
  
  <p>This is an abstract from <code>AndroidManifest.xml</code></p>
  
  <pre><code>&lt;uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <h1>Case1</h1>
  
  <p>if I try with this snippet (actually working on another project) </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var storagePath = "/storage/emulated/0";
  var fileDir = cordova.file.externalDataDirectory.replace(cordova.file.externalRootDirectory, '');
  var fileName = $scope.ngDocument.documentId + ".pdf"
  var filePath = storagePath + "/" + fileDir + fileName;
  $cordovaFile.writeFile(filePath, BINARY_ARR, {'append': false}).then(function(result) {}, function(err) {});</code></pre>
  </div>
  </div>
  </p>
  
  <p>I get <code>{"code":5,"message":"ENCODING_ERR"}</code> as Callback from the <code>$cordovaFile.writeFile</code>, no matter if I use absolute path, relative path, just the file name and no file is ever created.</p>
  
  <h1>Case2</h1>
  
  <p>With this snippet </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
    console.log('file system open: ' + fs.name);
    fs.root.getFile(fileName, { create: true, exclusive: false }, function (fileEntry) {
      console.log("fileEntry:" + JSON.stringify(fileEntry));
      writeFile(fileEntry, BINARY_ARR);
    }, function(data){});
  }, function(data){});</code></pre>
  </div>
  </div>
  </p>
  
  <p>happen two different things</p>
  
  <h2>Case 2.1</h2>
  
  <p>If no config options are specified in <code>config.xml</code> the app creates an empty folder into /storage/emulated/0/Android/media/{myAPP}</p>
  
  <h2>Case 2.2</h2>
  
  <p>with these two preferences</p>
  
  <pre><code>&lt;preference name="AndroidPersistentFileLocation" value="Compatibility" /&gt;
  &lt;preference name="AndroidExtraFilesystems" value="cache" /&gt;
  </code></pre>
  
  <p>a file in <code>/storage/emulated/0</code> (external SSD) is created and in <code>logcat</code>errors are:</p>
  
  <pre><code>E/Vold    ( 2280): Failed to find mounted volume for /storage/extSdCard/Android/data/{myApp}/files/
  W/Vold    ( 2280): Returning OperationFailed - no handler for errno 0
  W/ContextImpl(13364): Failed to ensure directory: /storage/extSdCard/Android/data/{myApp}/files
  E/Vold    ( 2280): Failed to find mounted volume for /storage/extSdCard/Android/data/{myApp}/files/
  W/Vold    ( 2280): Returning OperationFailed - no handler for errno 0
  W/ContextImpl(13364): Failed to ensure directory: /storage/extSdCard/Android/data/{myApp}/files
  E/Vold    ( 2280): Failed to find mounted volume for /storage/extSdCard/Android/data/{myApp}/cache/
  W/Vold    ( 2280): Returning OperationFailed - no handler for errno 0
  W/ContextImpl(13364): Failed to ensure directory: /storage/extSdCard/Android/data/{myApp}/cache
  </code></pre>
  
  <p>The strange fact is that <code>/storage/extSdCard</code> (symbolic link for <code>/mnt/extSdCard</code>) is not mounted while the external SSD is mounted on <code>/mnt/sdcard</code> </p>
  
  <p>Please help: I'm headbanging.<br>
  The first snippet was working as a charm in another project. Could it be the version of ngCordova? </p>