I considered a lot of questions, but this did not solve my problem.
I have already installed the plugin for files.
When I type the cordova ls plugin, I get the following result:
[ 'org.apache.cordova.file' ]
In androidmanifest.xml I have:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
And in app / res / xml / config.xml I have:
<feature name="File">
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>
This is my code:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);
}
function gotFile(file){
readDataUrl(file);
readAsText(file);
}
function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
console.log(evt.target.result);
};
reader.readAsDataURL(file);
}
function readAsText(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as text");
console.log(evt.target.result);
document.getElementById('file_status').innerHTML = evt.target.result;
};
reader.readAsText(file);
}
function fail(error) {
console.log(error.code);
}
What did I do wrong?
source
share