【问题标题】:Cordova/Phonegap install file to externalDataDirectoryCordova/Phonegap 安装文件到 externalDataDirectory
【发布时间】:2015-09-02 11:27:32
【问题描述】:
我正在使用the cordova file plugin 来读取和写入我的安卓设备上的文件。我想做的是将 json 文件“安装”到 cordova.file.externalDataDirectory 目录。该文件将包含应用程序的默认设置,但我希望用户也可以编辑这些设置(因此不能隐藏在应用程序沙箱中)。
我似乎无法找到一种方法来做到这一点。有可能吗?
我能想到的唯一选择是将默认设置文件安装到应用程序沙箱,然后在应用程序启动时将此文件复制到 cordova.file.externalDataDirectory 目录。这并不理想,但它可能是我必须走的路......
【问题讨论】:
标签:
cordova
cordova-plugin-file
【解决方案1】:
你应该使用这样的东西:
fileEntry.createWriter(function(fileWriter) {
// ...
var blob = new Blob(['{"key":"value"}'], {type: 'text/plain'});
fileWriter.write(blob);
}, function(e){console.log('Error')});
包裹在里面:
window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(fileEntry) {
// ...
});
我现在无法测试它,但我希望它有用。还要检查the filesystem api guide 和this tutorial。