gio*_*_13 8 javascript android phonegap-plugins cordova phonegap-build
我正在尝试通过应在iOS和Android上运行的在线构建服务构建PhoneGap应用程序,但这个问题主要集中在Android部分.
该应用程序的主要目标是能够访问和修改文件系统.受到Raymond Camden博客文章的启发,我最终编写了一个与他非常相似的示例应用程序,它使用读/写权限访问文件系统.主要区别在于我的应用程序是在线构建的,没有安装任何SDK,也没有关心任何androidManifes.xml文件.
我的问题是我能够访问文件系统(列表目录,读取文件),但我无法在其上写任何内容.
我在confix.xml中包含了必要的<feature />
标记,以获得文件访问权限:
<feature name="http://api.phonegap.com/1.0/file"/>
Run Code Online (Sandbox Code Playgroud)
以下是我的应用程序中使用的一些示例代码:
// Request fileSystem
fileSystem.root.getFile(fileName, {create:true}, readFile, onError);
// Function that reads a file
function readFile(file){
var reader = new FileReader();
reader.onloadend = function(e) {
console.log("contents: ", e.target.result);
}
reader.readAsText(file);
}
Run Code Online (Sandbox Code Playgroud)
fileSystem.root.getFile(fileName, {create:true}, function(file){
file.createWriter(function(writer) {
writer.onwrite = function() {
console.log('writing', arguments);
}
writer.onerror = function(e) {
console.error('error', e);
}
writer.onwriteend = function() {
console.log('writeend', arguments);
}
//Go to the end of the file...
writer.seek(writer.length);
// Append a timestamp
writerOb.write("Test at "+new Date().toString() + "\n");
})
}, onError);
Run Code Online (Sandbox Code Playgroud)
第二个代码示例不会在目标文件中写入任何内容,并且onerror
处理程序显示它是由于a NOT_FOUND_ERR
.这只是没有意义,因为我能够读取相同的文件(并且可以找到它).
以同样的方式,当我尝试创建一个新文件(使用相同的代码来写/附加文件代码,但目标文件不存在)时,我收到一个INVALID_MODIFICATION_ERR
错误.
我也在官方文档中尝试了这个例子,我得到了相同的结果(读取和不写入).
请注意,由于PhoneGap正在使用HTML5文件API,我试图通过blob编写内容,如此Stack Overflow应答(以及其他网站中)所示,没有任何运气.
我错过了什么?我是否需要一个单独的插件来编写文件,或者这是通过在线构建工具无法完成的事情,我必须下载SDK并以旧式方式编译应用程序?
PS:我的PhoneGap版本是2.3.0.
归档时间: |
|
查看次数: |
2594 次 |
最近记录: |