FileSystem root.fullPath возвращает неопределенное значение, а root.getFile выдает ошибку processMessage failed в phonegap.js

это мой первый вопрос здесь, так что извините, если я плохо пишу свой запрос. Я создаю проект с Sencha Touch 2.4.1 и PhoneGap (моя основная цель — Android), используя команду

sencha app build native

упаковать. Короче говоря, мне нужно запросить файловую систему, а затем загрузить какой-то файл (изображения). Согласно таким сообщениям, как этот, я пытаюсь использовать функцию "getFile()" перед началом загрузки, но даже такой простой код вызывает у меня проблемы:

Ext.define("MyApp.utils.Globals", {
    singleton: true,
    alias: 'widget.globals',
    config: {
        // Some vars not related to problem
    },
    constructor: function(config) {
        this.initConfig(config);
    },
    initFileSystem: function(quota) {
        if(Ext.browser.is.PhoneGap && !Ext.os.is.Desktop) {
            Ext.device.FileSystem.requestFileSystem({     
                type: window.PERSISTENT,
                size: quota,
                success: this.initFsSuccess,
                failure: this.initFsFailure
            });
        } else {
            window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
            window.requestFileSystem(window.PERSISTENT, quota, this.initFsSuccess, this.initFsFailure);
        }
    },
    initFsSuccess: function(fs) {
        // Save file system reference
        MyApp.app.fS = fs;      
        alert("FS: " + fs.root.fullPath); // This line outputs "FS: undefined"
        fs.root.getFile("newFile.jpg", {create: true, exclusive: false}, function(fileEntry){ alert("GetFile OK"); }, function(error){ alert("GetFile ERR"); });
    },
    initFsFailure: function(err) {
        console.log("File System Error " + err.code);
        Ext.Msg.show({
            title: 'FyleSystem Error',
            message: 'Can\'t access to FileSystem',
            buttons: [ { itemId: 'ok', text: 'Ok', ui: 'decline' } ],
            fn: Ext.emptyFn
        });
    }
});

Когда я пытаюсь получить доступ к корневому полному пути файловой системы (как в первом предупреждении в функции «initFsSuccess»), я получаю undefined в качестве значения. Кроме того, функция «getFile» перестает выполняться (обратный вызов не вызывается, успешно или неудачно), и в LogCat я вижу это:

01-12 12:22:20.669: D/CordovaLog(1625): file:///android_asset/www/phonegap.js: Line 1059 : processMessage failed: Error: TypeError: Cannot call method 'error' of undefined
01-12 12:22:20.669: I/Web Console(1625): processMessage failed: Error: TypeError: Cannot call method 'error' of undefined at file:///android_asset/www/phonegap.js:1059
01-12 12:22:20.669: D/CordovaLog(1625): file:///android_asset/www/phonegap.js: Line 1060 : processMessage failed: Stack: TypeError: Cannot call method 'error' of undefined
01-12 12:22:20.669: D/CordovaLog(1625):     at [object Object].getFile (file:///android_asset/www/app.js:1:498661)
01-12 12:22:20.669: D/CordovaLog(1625):     at [object Object].<anonymous> (file:///android_asset/www/app.js:1:617018)
01-12 12:22:20.669: D/CordovaLog(1625):     at file:///android_asset/www/app.js:1:495077
01-12 12:22:20.669: D/CordovaLog(1625):     at file:///android_asset/www/plugins/org.apache.cordova.file/www/requestFileSystem.js:52:25
01-12 12:22:20.669: D/CordovaLog(1625):     at success (file:///android_asset/www/plugins/org.apache.cordova.file/www/fileSystems-roots.js:40:13)
01-12 12:22:20.669: D/CordovaLog(1625):     at Object.callbackFromNative (file:///android_asset/www/phonegap.js:293:54)
01-12 12:22:20.669: D/CordovaLog(1625):     at processMessage (file:///android_asset/www/phonegap.js:1054:21)
01-12 12:22:20.669: D/CordovaLog(1625):     at Function.processMessages (file:///android_asset/www/phonegap.js:1091:13)
01-12 12:22:20.669: D/CordovaLog(1625):     at pollOnce (file:///android_asset/www/phonegap.js:956:17)
01-12 12:22:20.669: D/CordovaLog(1625):     at pollOnceFromOnlineEvent (file:///android_asset/www/phonegap.js:946:5)
01-12 12:22:20.669: I/Web Console(1625): processMessage failed: Stack: TypeError: Cannot call method 'error' of undefined
01-12 12:22:20.669: I/Web Console(1625):     at [object Object].getFile (file:///android_asset/www/app.js:1:498661)
01-12 12:22:20.669: I/Web Console(1625):     at [object Object].<anonymous> (file:///android_asset/www/app.js:1:617018)
01-12 12:22:20.669: I/Web Console(1625):     at file:///android_asset/www/app.js:1:495077
01-12 12:22:20.669: I/Web Console(1625):     at file:///android_asset/www/plugins/org.apache.cordova.file/www/requestFileSystem.js:52:25
01-12 12:22:20.669: I/Web Console(1625):     at success (file:///android_asset/www/plugins/org.apache.cordova.file/www/fileSystems-roots.js:40:13)
01-12 12:22:20.669: I/Web Console(1625):     at Object.callbackFromNative (file:///android_asset/www/phonegap.js:293:54)
01-12 12:22:20.669: I/Web Console(1625):     at processMessage (file:///android_asset/www/phonegap.js:1054:21)
01-12 12:22:20.669: I/Web Console(1625):     at Function.processMessages (file:///android_asset/www/phonegap.js:1091:13)
01-12 12:22:20.669: I/Web Console(1625):     at pollOnce (file:///android_asset/www/phonegap.js:956:17)
01-12 12:22:20.669: I/Web Console(1625):     at pollOnceFromOnlineEvent (file:///android_asset/www/phonegap.js:946:5) at file:///android_asset/www/phonegap.js:1060
01-12 12:22:20.669: D/CordovaLog(1625): file:///android_asset/www/phonegap.js: Line 1061 : processMessage failed: Message: S01 File1432781697 [{"fullPath":"\/","filesystemName":"temporary","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/cache\/","filesystem":0,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"persistent","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"content","isDirectory":true,"nativeURL":"cdvfile:\/\/localhost\/content\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files-external","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"documents","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/files\/Documents\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"sdcard","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache-external","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"root","isDirectory":true,"nativeURL":"file:\/\/\/","filesystem":1,"isFile":false,"name":""}]
01-12 12:22:20.669: I/Web Console(1625): processMessage failed: Message: S01 File1432781697 [{"fullPath":"\/","filesystemName":"temporary","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/cache\/","filesystem":0,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"persistent","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"content","isDirectory":true,"nativeURL":"cdvfile:\/\/localhost\/content\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files-external","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"documents","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/files\/Documents\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"sdcard","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache-external","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"root","isDirectory":true,"nativeURL":"file:\/\/\/","filesystem":1,"isFile":false,"name":""}] at file:///android_asset/www/phonegap.js:1061

Спасибо всем за советы за любую помощь, я постараюсь предоставить любую другую информацию/спецификации, если это необходимо.


person MatteoBelfiori    schedule 12.01.2015    source источник


Ответы (1)


Решение найдено (даже если я не знаю почему...)! Вот что я сделал:

1) В моем файле "app.js" я удалил

'Ext.device.FileSystem'

строка из раздела «требуется»;

2) Заменено тело функции "initFileSystem()", о которой сообщалось в первом посте, на это

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(window.PERSISTENT, quota, this.initFsSuccess, this.initFsFailure);

Работает в:

  • Google Chrome v. 39.0.2171.95 m (режим устройства вкл. и выкл.);
  • Мой Samsung Galaxy S4 (GT-I9515) под управлением официального Android 4.4.2 (как родное приложение, а не через браузер):
  • Эмулятор Android (я работаю на ПК с Windows 7) под управлением Android 4.1.1 с Intel Atom x86 в качестве процессора
person MatteoBelfiori    schedule 12.01.2015