3

I'm working on an android app based on phonegap 4.0 & wikitude. I want to create a folder on root (/storage/emulated/0/ or /storage/sdcard0 if there's a SD). The piece of code for doing that is:

onDeviceReady: function() {

    app.receivedEvent('deviceready');
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
    app.wikitudePlugin = cordova.require("com.wikitude.phonegap.WikitudePlugin.WikitudePlugin");
    app.wikitudePlugin.isDeviceSupported(app.onDeviceSupportedCallback, app.onDeviceNotSupportedCallback);  


},  

gotFS: function(fileSystem) {

    alert( "Got the file system: "+fileSystem.name +"<br/>" +
            "root entry name is "+fileSystem.root.name + "<p/>");
    fileSystem.root.getDirectory("ARMedia", {create: true}, gotDir, fail);

},

gotDir: function(dirEntry) {

    file.entry = fileEntry;
    alert('Folder ARMedia created!');   
},

fail: function(error) {

    alert(error);
},

The problem is that when I test on my devices (xiaomi mi3 and a Samsung galaxy tab 2) the app is stuck on "window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);"

The plugins for file-transfer and file are already in my plugins folder, the android manifest.xml has the permission of WRITE_EXTERNAL_STORAGE and I've tried all almost everything... I just want to know why the program doesn't go farther of window.requestFileSystem.

Thanks and sorry for my bad english.

LordTobar
  • 51
  • 1
  • 7

2 Answers2

0

Most likely it is this: LocalFileSystem.PERSISTENT. I believe you mean window.PERSISTENT or window.TEMPORARY.

Raymond Camden
  • 10,661
  • 3
  • 34
  • 68
  • Which are the differences between LocalFileSystem and window? – LordTobar Feb 05 '15 at 11:58
  • Window is an object available to JavaScript, LocalFileSystem is not (afaik). – Raymond Camden Feb 05 '15 at 12:00
  • 1
    Still not working, although all the examples on the internet of window.requestFileSystem are with LocalFileSystem. ie: http://docs.phonegap.com/en/edge/cordova_file_file.md.html – LordTobar Feb 05 '15 at 12:05
  • True. The HTMLRocks article (http://www.html5rocks.com/en/tutorials/file/filesystem/) shows it as part of Window though. I think I see another issue. You use gotFS as a key of anther object not shown above. Can you edit your Q to show more of the JS? – Raymond Camden Feb 05 '15 at 12:22
-1

As you can see on , html 5 file system API docs, for persistent storage, the second argument of window.requestFileSytem() is the quota, "Size (in bytes) the app will require for storage." If you set it to Zero, the filesystem might be useless.

To see if the you are allowed to request a certain amount of memory, you should follow the docs advises :

To use PERSISTENT storage, you must obtain permission from the user to store peristent data. The same restriction doesn't apply to TEMPORARY storage because the browser may choose to evict temporarily stored data at its discretion.

To use PERSISTENT storage with the FileSystem API, Chrome exposes a new API under window.webkitStorageInfo to request storage:

window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024, function(grantedBytes) {
    window.requestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler)
    ;
}, function(e) {
    console.log('Error', e);
});

Once the user has granted permission, there's no need to call requestQuota() in the future (unless you wish to increase your app's quota). Subsequent calls for equal or lesser quota are a noop.

Loui Ty
  • 1
  • 1