I am trying to display a list of file that are store on the android device in my cordova app and I am using the cordova -file plugin .However, I am not seeing the file when I select the browse button in my app but I see the file in the system "My Files" android app.
Here is the list of folder that I am iterating thru
[cordova.file.externalRootDirectory,cordova.file.dataDirectory]
On the android phone, I see the files bu doing the following:
select /settings/storage/internal storage
selecting explore
On the emnu the heading says MyFiles>device storage
select data or download ..
On the device cordova.file.externalRootDirectory resolve to file:///storage/emulated/0/download
However, I don't see any files
Here my code
$scope.showLocalFileOnAndroid = function () {
$scope.showLocalAndroidFiles = true;
var localURLs = [cordova.file.externalRootDirectory,cordova.file.dataDirectory
];
var index = 0;
var i;
var errorStr = '';
var fileList = [];
var addFileEntry = function (entry) {
var dirReader = entry.createReader();
dirReader.readEntries(
function (entries) {
var i;
for (i = 0; i < entries.length; i++) {
if (entries[i].isDirectory === true) {
// Recursive -- call back into this subdirectory
addFileEntry(entries[i]);
} else {
var ext = entries[i].name.split('.').pop();
if (ext === 'doc' || ext === 'docx' ||
ext === 'rdf' || ext === 'pdf' || ext === 'txt' ||
ext === 'odt') {
fileList.push(entries[i]); // << replace with something useful
}
index++;
}
}
},
function (error) {
console.log('readEntries error: ' + error.code);
errorStr += '<p>readEntries error: ' + error.code + '</p>';
}
);
};
var addError = function (error) {
console.log('getDirectory error: ' + error.code);
errorStr += '<p>getDirectory error: ' + error.code + ', ' + error.message + '</p>';
};
for (i = 0; i < localURLs.length; i++) {
if (localURLs[i] === null || localURLs[i].length === 0) {
continue; // skip blank / non-existent paths for this platform
}
window.resolveLocalFileSystemURL(localURLs[i], addFileEntry, addError);
}
$scope.fileList = fileList;
$scope.localFileError = errorStr;
};