2015-01-12 3 views
1

это мой первый вопрос, так что извините, если я пишу плохо свой запрос. Я создаю проект с Сенча Touch, 2.4.1 и PhoneGap (моя основная цель Android), с помощью командыFileSystem root.fullPath возвращает undefined и root.getFile дает «processMessage failed error» в phonegap.js

sencha app build native 

для упаковки. Короче говоря, мне нужно запросить файловую систему, а затем загрузить файл (изображения). По постам как this, я пытаюсь использовать функцию «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 
     }); 
    } 
}); 

При попытке получить доступ к корневому файловой системе полным path (как в первом предупреждении в функции 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 

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

ответ

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 м (режим устройства на & выключен);
  • My samsung Galaxy S4 (GT-I9515) работает с официальным Android 4.4.2 (как родное приложение, а не через браузер):
  • Android Emulator (я на компьютере с Windows 7) работает под управлением Android 4.1.1 с Intel Atom x86 в качестве ЦП
Смежные вопросы