使用Cordova文件插件版本1.3.3在Android5.1,Nexus 10上创建和写入文件,
>按照指南https://github.com/apache/cordova-plugin-file,并匹配此链接所需的内容.
>添加清单权限:android.permission.WRITE_EXTERNAL_STORAGE
> requestFileSystem接口返回的文件夹是“file:/// storage / emulated / 0 /”,我们可以访问.
>尝试了两个选项,得到同样的错误:
preference name =“AndroidPersistentFileLocation”value =“Internal”
preference name =“AndroidPersistentFileLocation”value =“兼容性”
示例代码:
var fileInfo = new Object();
fileInfo.createFile = true;
fileInfo.filename = "test.txt";
fileInfo.content = "test";
fileInfo.success = function(){alert("file Info success");};
fileInfo.error = function() {alert("file Info error");};
_write0 = function() {
if(fileInfo.createFile) {
var _write1 = function(downloadFolder) {
theFileSystem.root.getFile(downloadFolder+"/"+fileInfo.filename,{create:true},function(f){
f.createWriter(function(writer){
var _write2 = function() {
writer.onwriteend = function(evt) {
fileInfo.success();
};
var raw = atob(fileInfo.content);
var rawLength = raw.length;
var contentArray = new Uint8Array(new ArrayBuffer(rawLength));
for(var i=0;i<rawLength;i++) {
contentArray[i] = raw.charCodeAt(i);
}
var contentBlob = new Blob([contentArray.buffer]);
writer.write(contentBlob);
};
writer.onwriteend = function(evt){_write2();};
writer.onerror = function(evt){fileInfo.error();};
writer.truncate(0);
});
}, function(data){alert("Create File Failed."); alert(data);});
};
_write1("File/myApp");
}
};
requestFileSystem(PERSISTENT,1024*1024,function(fs){
theFileSystem = fs;
_write0();
},function(data){alert("requestFileSystem Failed."); alert(data);});
错误INVALID_MODIFICATION_ERR(9)在执行接口DirectoryEntry.prototype.getFile时抛出.
那么这个插件所需的任何其他配置都适用于Android 5.1?
顺便说一句,代码在iPad上正常运行.
解决方法:
确保在应用程序权限中启用了存储.
当App尝试请求不存在的文件系统时,抛出INVALID_MODIFICATION_ERR.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。