[英]How to write files on external sdcard (physical card) with Phonegap/Cordova on Android?
[英]how to get list of folders of phone's sdcard(External Memory Card) in phonegap
我正在使用phonegap的文件使用此代码列出电话内的所有文件夹。
document.addEventListener("deviceready", makeFileSystemReady, true);
var globalFileSystem;
function makeFileSystemReady(){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemError);
}
function onFileSystemSuccess(fs){
globalFileSystem=fs; //Initialized the global file system.
}
function onFileSystemError(){
console.log("Unable to load the file System Plugin");
}
function chooseFromGallery(){
var dirReader = globalFileSystem.root.createReader();
dirReader.readEntries(galleryFiles,galleryFilesErrors);
}
function galleryFiles(entries){
var s = "<p style='color:white'>";
console.log(globalFileSystem.root);
for(var i=0,len=entries.length; i<len; i++) {
//entry objects include: isFile, isDirectory, name, fullPath
s+= entries[i].fullPath;
if (entries[i].isFile) {
s += " [F]";
}
else {
s += " [D]";
}
s += "<br/>";
}
s+="<p/>";
document.getElementById('videoArea').innerHTML=s;
}
function galleryFilesErrors(){
alert("Unable to use the file system !");
}
这段代码可以正常工作,但是这里的问题是,如何获取SD卡或手机外部存储中的文件夹列表。
cordoba-plugin-file的文档包含不同位置的标识符。
https://github.com/apache/cordova-plugin-file
在这种情况下,您要使用cordova.file.externalRootDirectory,当将其传递给window.resolveLocalFileSystemURL()时,它将解析为正确的目录条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.