科尔多瓦在SD卡内创建一个文件夹 - 内部或外部


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]。现在,当我在真正的Android设备上创建此文件夹时,路径为:file:///data/data/com.packagename/files/files/productpictures。

那么,有什么方法可以在其他地方创建此文件夹,Android设备用户即使在关闭应用程序后也可以轻松访问。我想创建此文件夹[产品图片],如SD卡/产品图片或Android照片库或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 这样的位置太复杂了。

提前感谢您的帮助。

此示例代码允许您在 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
    }

最新更新