2016-05-07 17 views
0
function creatingFolder(fileSystem) { 
      var entry = fileSystem.root; 
      entry.getDirectory("productpictures", {create: true, exclusive: false}, win, error); 
      window.newfolder = fileSystem.root.toURL()+"/productpictures"; 

     } 

     function win(dir) { 
      alert("Created dir with name: "+dir.name); 
      alert("Created dir at: "+dir.toURL()); 
      alert("Created dir NativePath: " + dir.nativeURL); 
      alert('done '+window.newfolder); 
     } 

     function error(error){ 
       alert('hmm: '+error.code+' message: '+error.message); 
     } 

好的,所以[productpictures]是我的应用程序将创建的文件夹,应用程序用户可以将文件下载到此[productpictures]文件夹中。我的问题是,如何让我的应用用户在关闭应用后访问此文件夹[productpictures]。现在,当我在真实的Android设备上创建该文件夹时,路径为:file:///data/data/com.packagename/files/files/productpictures。科尔多瓦在SD卡内部创建文件夹 - 内部或外部

那么,有什么方法可以在Android设备用户即使关闭应用程序后也可以轻松访问的地方创建此文件夹。我想创建这个文件夹[productpictures],如sdcard/productpictures或安卓照片库或Android设备的下载文件夹。

我尝试过的另一个代码,但没有工作;

function creatingFolder(fileSystem) { 
      var entry = fileSystem.root; 
      entry.getDirectory(cordova.file.externalRootDirectory+"/productpictures", {create: true, exclusive: false}, win, error); 
      window.newfolder = cordova.file.externalRootDirectory+"/productpictures"; 

     } 

所以,还没有找到任何资源在线来完成这个。我想要这个功能,因为用户应该能够发送或共享[productpictures]文件夹内的文件,并将此文件夹放置在像file://data/data/com.package/files/files/productpictures这样的位置太复杂。

感谢您的帮助。

回答

1

此示例代码,您可以在外部根目录中的Android和文件夹中的iOS创建文件夹:

function writeFile() { 
      if (sessionStorage.platform.toLowerCase() == "android") { 
       window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, onFileSystemSuccess, onError); 
      } else { 
       window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onError); 
      } 
    }  

    function onError(e) { 
     alert("onError"); 
    }; 

    function onFileSystemSuccess(fileSystem) { 
     var entry = ""; 
     if (sessionStorage.platform.toLowerCase() == "android") { 
      entry = fileSystem; 
     } else { 
      entry = fileSystem.root; 
     } 
     entry.getDirectory("Folder_Name", { 
      create: true, 
      exclusive: false 
     }, onGetDirectorySuccess, onGetDirectoryFail); 
    }; 

    function onGetDirectorySuccess(dir) { 
     dir.getFile(filename, { 
      create: true, 
      exclusive: false 
     }, gotFileEntry, errorHandler); 
    }; 

    function gotFileEntry(fileEntry) { 
     // logic to write file in respective directory 
    }; 

    function errorHandler(e) { 
     // handle error 
    } 
相关问题