【发布时间】:2014-04-04 16:24:25
【问题描述】:
问题描述:
我可以使用文件或文件系统根(读写)访问内部存储。但是这样的文件不能从其他应用程序访问。例如,如果我想通过 emailComposerPlugin 发送此文件,则电子邮件客户端无法访问该文件。 (“打开方式”功能也是如此。)
如果我将选项 {sandboxed: true} 更改为 false(写入外部存储),它不起作用并最终出现 FileUtils.UNKNOWN_ERR。我在手机与 USB 断开连接时尝试了该应用程序,因为一些文档提到在安装在 pc 上时无法访问外部存储 - 但结果相同。
根据我在mailing list 上读到的内容,这应该是可能的。看来我错过了一个关键点?
背景: 我尝试让为 iPhone 创建的混合应用程序在 android 设备上运行。为了有一个小操场,我创建了一个小型测试项目。
编辑: 文件系统根目录和文件插件之间似乎存在问题。但我有他们两个的最新版本。 (文件:1.0.1 文件系统根目录:0.1.0) 调试文件系统和文件类表明
private String fullPathForLocalURL(Uri URL) {
if (FILESYSTEM_PROTOCOL.equals(URL.getScheme()) && "localhost".equals(URL.getHost())) {
String path = URL.getPath();
if (URL.getQuery() != null) {
path = path + "?" + URL.getQuery();
}
return path.substring(path.indexOf('/', 1));
// path = "/cache-external" at this point
// results in index out of bounds exception
我尝试了什么?
config.xml
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external" />
AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
javascript 代码
function createTextDocument(filename, text) {
cordova.filesystem.getDirectoryForPurpose('cache', {sandboxed: false}, successCallback, failureCallback);
function successCallback(directoryEntry){
console.log('directory found (cordova): ' + directoryEntry.toURL());
console.log('directory found (native) : ' + directoryEntry.toNativeURL());
directoryEntry.getFile(filename, {create: true, exclusive: false},
function(fileEntry){
var filePath = fileEntry.toNativeURL();
fileEntry.createWriter(
function(fileWriter){
console.log('start writing to: ' + filePath );
fileWriter.write(text);
console.log('file written');
},failureCallback
);
}, failureCallback
);
}
function failureCallback(error){
console.log('error creating file: ' + error.code);
// results in code 1000
}
}
【问题讨论】: