Using Cordova file plugin version 1.3.3 to create and write file on Android5.1, Nexus 10,
Tried two options, get the same error:
preference name="AndroidPersistentFileLocation" value="Internal"
preference name="AndroidPersistentFileLocation" value="Compatibility"
Sample code:
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);});
Error INVALID_MODIFICATION_ERR(9) throws when executing into interface DirectoryEntry.prototype.getFile .
So any other configuration needed for this plugin worked on Android 5.1?
BTW, the code working correctly on iPad.
This solution works for me. Edit the config file to this:
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" android:requestLegacyExternalStorage="true"/>
</edit-config>
</plataform>
Found solution here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With