【发布时间】:2015-01-21 16:41:06
【问题描述】:
我尝试将本地生成的文件下载到设备文件系统。我正在使用一个仅适用于 chrome 的函数,所以我想用基于 Cordova 的函数替换它。我在 IntelXDK 中添加了:
-Cordova 插件 File 和 FileTransfer。
-Android 权限 WRITE_EXTERNAL-STORAGE 和 READ_EXTERNAL_STORAGE。
-下载功能:
function downloadCordova2(filename, text){
//NEXT SAVE IT TO THE DEVICE'S LOCAL FILE SYSTEM
console.log("file system...");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
alert("in 1");
console.log(fileSystem.name);
console.log(fileSystem.root.name);
console.log(fileSystem.root.fullPath);
fileSystem.root.getFile("test.txt", {create: true}, function(entry) {
var fileEntry = entry;
console.log(entry);
alert("in 2");
entry.createWriter(function(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
console.log("writing to file");
writer.write( pdfOutput );
}, function(error) {
console.log(error);
});
}, function(error){
console.log(error);
});
},
function(event){
console.log( evt.target.error.code );
alert(evt.target.error.message);
});
}
我在模拟器中、在为 chrome 构建后在 chrome 中、在使用真正的 Android 设备的模拟器中收到错误“Uncaught ReferenceError: LocalFileSystem is not defined”,当我安装 Android apk 时,我看不到它,但它也不行。
我错过了什么吗? 关于这个问题有类似的帖子,但是缺少插件,权限的问题......
【问题讨论】:
标签: javascript android cordova intel-xdk