Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting application directory in phone gap

Tags:

cordova

Using the file api of phone gap build, I want to get the application directory in which all files should be stored.

What command do I need to use?

like image 299
Neeraj Avatar asked Aug 01 '12 16:08

Neeraj


2 Answers

You can use cordova.file.applicationDirectory for getting your app directory. It will resolve to file:///android_asset/ in android and /var/mobile/Applications//.app/ in IOS

You can get all your app files in the www directory in both android and iOS.

window.resolveLocalFileSystemURL(cordova.file.applicationDirectory+'www/index.html',success,fail);
function success(fileEntry){
console.log("got the file object")
}
function fail(error){
console.log("error");
}

for getting the app directory on the filesystem where your app files will be stored can be get by cordova.file.applicationStorageDirectory which further contains two directories files and cache both are persistent.

you can check the link for further details..

https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md

like image 32
Satpal Tanan Avatar answered Oct 26 '22 23:10

Satpal Tanan


function gotFS(fileSystem) {
    console.log("got filesystem");
    // save the file system for later access
    console.log(fileSystem.root.fullPath);
    window.rootFS = fileSystem.root;
}

document.addEventListener('deviceready', function() {                
    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}, false);

With this code you'll have a DirectoryEntry object for the root directory of your app stored in the global variable "rootFS". You can get the path of that folder like this:

rootFS.fullPath
like image 175
davids Avatar answered Oct 27 '22 00:10

davids