我试图显示在我的cordova应用中存储在android设备上的文件列表,但我正在使用cordova -file插件。但是,我在我的应用程序中选择浏览按钮时没有看到该文件,但我在系统“我的文件”Android应用程序中看到该文件。没有看到使用cordova -file插件存储在Android设备上的文件
这里是文件夹,我遍历通
[cordova.file.externalRootDirectory,cordova.file.dataDirectory]
在Android手机列表中,我看到了文件BU执行以下操作:
- 选择/设置/存储/内部存储
- 选择探索
- 在emnu标题说MYFILES>设备存储
选择数据或下载..
在设备 cordova.file.externalRootDirectory决心文件:///存储/模拟/ 0 /下载
不过,我没有看到任何文件
这里我的代码
$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;
};
可能的重复的未答复的问题在这里:http://stackoverflow.com/questions/40557762/list-the-files-that-are-stored-in-the-download-folder-on-an-android-device – Matthias
谢谢..我看到了答案,并且我复制了一些代码,但是它不起作用。设备上的文件存储在“Internal Storage \ root \ sdcard \ Download”中,并且没有在该代码中定义的路径请参考此路径 – user2570135
这似乎是一个常见问题,[另一个未解答的问题](http://stackoverflow.com/questions/41152137/cordova-file-download-to-android-download-folder)有关科尔多瓦和下载文件夹。 – Matthias