2013-06-21 2 views
0

Phonegap 2.2.0을 사용하고 있습니다. 이미지 저장 경로가있는 안드로이드 장치에서 모든 이미지/사진/바탕 화면을 가져오고 싶습니다. 지금까지 내가했던 는Sdcard의 모든 이미지 표시

<!DOCTYPE html> 
<html> 
    <head> 

    <script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script> 
    <script type="text/javascript" charset="utf-8"> 

    document.addEventListener("deviceready",onDeviceReady,false); 

    function onDeviceReady() { 
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, onFail); 
    } 

    function onFail(message) { 
     alert('Failed because: ' + message); 
    } 

    function gotFS(fileSystem) { 
     fileSystem.root.getFile("1.jpg", {create: true}, gotFileEntry, fail); 
    } 

    function gotFileEntry(fileEntry) { 
     fileEntry.file(gotFile, fail); 
    } 

    function gotFile(file){ 
     readDataUrl(file); 
    } 

    function readDataUrl(file) { 
      var reader = new FileReader(); 
      reader.onloadend = function(evt) { 
      console.log("Read as data URL"); 
      console.log(evt.target.result); 
      document.getElementById("smallImage").style.display='block'; 
      document.getElementById("smallImage").src = evt.target.result; 
     }; 
     reader.readAsDataURL(file); 
    } 

    function fail(evt) { 
     console.log(evt.target.error.code); 
    } 
    </script> 
    </head> 
    <body> 
    <img style="display:none;width:60px;height:60px;" id="smallImage" src="" /> 
    <img style="display:none;" id="largeImage" src="" /> 
    </body> 
</html> 

코드가 나에게 단 하나의 이미지를 제공합니다,하지만 난 모든 이미지를 원한다. 제안 사항이 좋을 것입니다.

감사합니다.

답변

0

당신은 .svg 파일을 찾고 모든 항목을 통해 루트 FS 및 루프에서 DirectoryReader을 작성해야합니다.

function gotFS(fileSystem) { 
    var reader = fileSystem.root.createReader(); 
    reader.readEntries(gotList, fail)l 
} 

function gotList(entries) { 
    var i; 
    for (i=0; i<entries.length; i++) { 
     if (entries[i].name.indexOf(".svg") != -1) { 
      uploadPhoto(entries[i].fullPath); 
     } 
    } 
} 
관련 문제