2012-11-04 2 views
2

phonegap/cordova를 사용하여 앨범에서 여러 사진을 선택할 수 있는지 아는 사람 있습니까?phonegap/cordova 여러 사진 선택

문서를 사용하여 하나의 사진을 선택하는 앱을 만드는 것은 쉽지만 여러 장의 사진을 선택하는 방법은 문서화되어 있지 않습니다.

어쩌면 플러그인 (iOS/Android)이 필요합니까? 또는 해결 방법은 무엇입니까? 이 문제는 저를위한 쇼 스토퍼이므로 괜찮은 해결책이 될 것입니다.

+0

안녕하세요! 이 문제를 해결할 수 있었습니까? IOS/Android phonegap APP에 대해 설명하는 것과 동일한 기능이 필요합니다. 감사합니다 –

+0

안녕 친구! 안타깝게도 안됩니다 : (아직 Phonegap에서 구현되지 않았습니다.) –

+0

답장을 보내 주셔서 감사합니다. 다음 해결 방법을 찾을 필요가 있습니다 :-(안부 –

답변

3

현재 핵심 API에서는 기능을 사용할 수 없습니다. 그러나 개선 요청이 열려 있습니다. 이 시점에서 가장 좋은 방법은 플러그인을 작성하는 것입니다.

+0

JIRA 티켓에 대한 의견은이 기능이 코어에 추가되지 않는다는 것을 나타냅니다. 플러그인을 작성할 수는 있지만 가능한 경우 플러그인을 작성하는 사람/https://issues.apache.org/jira/browse/CB-1215 – talentedmrjones

3

다중 선택의 경우 모든 디렉토리를 반복적으로 반복하여 이미지를 찾는 파일 플러그인을 사용했습니다. 숨김 파일을 무시합니다.

var numDirs = 0; 
var numFiles = 0; 
var ImageFilePath = new Array(); 

function GetAllImageFromSD() { 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail); 

} 

function onFileSystemSuccess(fileSystem) { 
    fileSystem.root.getDirectory("/sdcard", { create: false, exclusive: false }, getDirSuccess, fail); 
} 

function getDirSuccess(dirEntry) { 
    var directoryReader = dirEntry.createReader(); 

    // Get a list of all the entries in the directory 
    directoryReader.readEntries(readerSuccess, fail); 
} 


var readerTimeout = null, millisecondsBetweenReadSuccess = 1000; 

function readerSuccess(entries) { 
    String.prototype.startsWith = function (str) 
    { return (this.match("^" + str) == str) } 

    var i = 0, len = entries.length; 
    for (; i < len; i++) { 
     if (entries[i].isFile) { 
      if ((entries[i].name.indexOf(".jpeg") != -1) || (entries[i].name.indexOf(".png") != -1) || (entries[i].name.indexOf(".jpg") != -1)) { 
       var fileName = entries[i].name; 
       if (!fileName.startsWith(".")) { 
        numFiles++; 
        ImageFilePath.push(entries[i].fullPath) 
        // console.log("file "+entries[i].fullPath) 
       } 
      } 

     } else if (entries[i].isDirectory) { 
      numDirs++; 
      // console.log("directory "+entries[i].name) 
      var dirName = entries[i].name; 
      if (!dirName.startsWith(".")) { 
       getDirSuccess(entries[i]); 
      } 
     } 
     if (readerTimeout) { 
      window.clearTimeout(readerTimeout); 
     } 
    } 
    if (readerTimeout) { 
     window.clearTimeout(readerTimeout); 
    } 
    readerTimeout = window.setTimeout(weAreDone, millisecondsBetweenReadSuccess); 
} 

function weAreDone() { 

console.log("numDirs " + numDirs); 
console.log("numFiles " + numFiles); 

var a = ""; 

var GalleryImageTag = ""; 
GalleryImageTag = "<div class='spacingbox'></div> "; 

for (var j = 0; j < ImageFilePath.length; j++) { 
    GalleryImageTag += "<div class='divgallery divcolor'>" 
    var ChkId = "chk" + j; 
    GalleryImageTag += "<img class='imggallery' id='" + j + "' src=' " + ImageFilePath[j] + "'alt=''/>"; 
    GalleryImageTag += "<input id='" + ChkId + "' name='" + ChkId + "' type='checkbox' value='" + ImageFilePath[j] + "' class='allignchk'>"; 
    GalleryImageTag += "</div>"; 

} 
$('#ImageContainer').html(''); 
$('#ImageContainer').append(GalleryImageTag); 
$('#GalleryView').popup("open"); 
numDirs = 0; 
numFiles = 0; 

ImageFilePath = []; 
console.log(GalleryImageTag); 
} 

이 코드는 많은 양의 이미지가 있으면 완료하는 데 시간이 걸릴 수 있습니다.

+0

을 말하지 않습니다. – Vini