希望有人能解决这个问题,我一整天都在与这个问题作斗争。
我正在尝试浏览文件系统中的文件夹以选择文件,但似乎无法连接到文件系统。
每当我调用“window.requestFileSystem”时,错误回调返回“未找到类”的错误。进入Cordova的“requestFileSystem”函数时,我注意到“Class not found”是在exec()调用期间返回的(我无法跟踪它)。
有没有人解决过这个问题或知道如何解决?我知道它在几个论坛上都有提到,但那里提出的解决方法对我不起作用。
就我所看到的,所有插件都在那里。使用Cordova CLI安装后,它们会出现在插件文件夹中。我确实想知道文件插件是否被加载,不确定我该如何验证它。
- org.apache.cordova.console
- org.apache.cordova.device
- org.apache.cordova.file
- org.apache.cordova.file-transfer
www/index.html
<body onload="onLoad();">
<script type="text/javascript">
// Init when we're good and ready.
function onLoad(){document.addEventListener('deviceready', init, true);}
// Init :)
function init(){
// window.requestFileSystem is recognized, so far so good.
window.requestFileSystem(1, 0, function(fileSystem){
alert('success');
}, function(e){
// 'e' is an object, {code: 'Class not found'}
alert('Error accessing local file system');
});
}
</script>
<div class="app">
<h1>Apache Cordova</h1>
...
</div>
<script type="text/javascript" src="cordova.js"></script>
</body>
config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.fwd.cwptakeonsheetsv1" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>CWPTakeOnSheetsV1</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<feature name="File">
<param name="android-package" value="org.apache.cordova.file" />
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
<param name="onload" value="true" />
<param name="android-package" value="org.apache.cordova.FileUtils" />
</feature>
<feature name="FileTransfer">
<param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>
</widget>
Cordova的requestFileSystem.js
/**
* Request a file system in which to store application data.
* @param type local file system type
* @param size indicates how much storage space, in bytes, the application expects to need
* @param successCallback invoked with a FileSystem object
* @param errorCallback invoked if error occurs retrieving file system
*/
var requestFileSystem = function(type, size, successCallback, errorCallback) {
argscheck.checkArgs('nnFF', 'requestFileSystem', arguments);
var fail = function(code) {
errorCallback && errorCallback(new FileError(code));
};
if (type < 0) {
fail(FileError.SYNTAX_ERR);
} else {
// if successful, return a FileSystem object
var success = function(file_system) {
if (file_system) {
if (successCallback) {
// grab the name and root from the file system object
var result = new FileSystem(file_system.name, file_system.root);
successCallback(result);
}
}
else {
// no FileSystem object returned
fail(FileError.NOT_FOUND_ERR);
}
};
// The error happens in exec()
exec(success, fail, "File", "requestFileSystem", [type, size]);
}
};
<feature>
行不应该出现在根config.xml中,而应该由cli platforms/android/res/xml/config.xml在安装插件时自动添加。也许你在平台的config.xml中重复了这些行? - QuickFix