2016-09-05 5 views
0

私のようなパスを持っているように、私は、内部ストレージ(ないwww DIR)のAndroid用コルドバでディレクトリを作成する方法を探しています:内部ストレージにフォルダを作成する方法は?

  • /mnt/sdcard/myfolder/
  • /sdcard/myfolder/
  • /storage/emulated/0/myfolder/

私が見つけた(これらのパスは、物理的に同じです)一部のスクリプトはwwwディレクトリ内で動作しますが、内部ストレージにフォルダを作成するにはどうすればよいですか?

ありがとうございます!

答えて

1

このサンプルコードを使用すると、iOS版でAndroidとドキュメントフォルダ内の外部のルートディレクトリにフォルダを作成することができます:

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 
} 
+0

は完璧に動作します!ありがとうございました! – krmax44

関連する問題