How to create a Folder inside Android Device inside sdcard > myNewDirectory

931 views
Skip to first unread message

Windows Tech Support

unread,
May 7, 2016, 12:11:44 PM5/7/16
to phonegap
CreateFolder();
function CreateFolder(){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, creatingFolder, error);
}
function creatingFolder(fileSystem) {
var entry = fileSystem.root;
entry.getDirectory("myNewDirectory", {create: true, exclusive: false}, win, error);
window.newfolder = fileSystem.root.toURL()+"/myNewDirectory";

}

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);
}

   Ok, so i can create this directory inside a real android device. My big confusion is after creating this folder, how do i access this [myNewDirectory]
   folder from my Android device because the location of this directory looks like file:///data/data/com.packagename/files/files/myNewDirectory 

   I want my app users to download file and store inside [myNewDirectory] folder. So, they need a way to access all the downloaded files after
   they close the app. How do i allow my app to create a folder inside my android device sdcard. 
   
   Something like this:
    function creatingFolder(fileSystem) {
var entry = fileSystem.root;
entry.getDirectory(cordova.file.externalRootDirectory+"myNewDirectory", {create: true, exclusive: false}, win, error);
}

   This code doesn't work though.

   Need some help here, its been two days now, wrapping my head with lots of online resources, still no success.

   Thanks.

Kerri Shotts

unread,
May 8, 2016, 10:15:38 PM5/8/16
to phonegap
Can you post what is logged to the JS Console and device console (adb logcat)? That might help see what's going on.

I think this documentation may be of help, though: https://github.com/apache/cordova-plugin-file#where-to-store-files. Note that the docs suggest using "window.resolveLocalFileSystemURL" to get a directory entry. So you could do something like this (completely off the top of my head, so it may need some tweaking):

function createFolder(win, error) {
    window
.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function (entry) {

        entry
.getDirectory("myNewDirectory", {create: true, exclusive: false}, win, error);

   
});
}




On Saturday, May 7, 2016 at 11:11:44 AM UTC-5, Windows Tech Support wrote:
...
Reply all
Reply to author
Forward
0 new messages