Android - Phonegap - 如何获取所拍照片的文件名

时间:2011-09-05 01:16:25

标签: android cordova

所以当我拍照时,他们会被保存到DCIM / Camera /目录。我需要在通过电子邮件发送后检索图片。

如何获取上一张照片的名称? (或调整我当前的代码以自定义文件名。)

以下是拍照的代码:

function capturePhoto(id) { 
navigator.camera.getPicture(onSuccess, onFail, { quality: 20,
destinationType: Camera.DestinationType.FILE_URI });    

function onSuccess(imageURI) {  
var image = document.getElementById(id);  

image.style.display = 'block'; 
image.src = imageURI;  

}   

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

2 个答案:

答案 0 :(得分:8)

这是我的问题的答案。你必须运行Phonegap 1.0。这将把图片放在你想要的地方,并根据你的需要命名。那么你可以通过文件名引用并随心所欲地做它。

var gotFileEntry = function(fileEntry) { 
            console.log("got image file entry: " + fileEntry.fullPath); 
            var gotFileSystem = function(fileSystem){ 
                // copy the file 
                fileEntry.moveTo(fileSystem.root, "pic.jpg", null, null); 
           }; 
            // get file system to copy or move image file to 
            window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, fsFail); 
        }; 
        //resolve file system for image  
        window.resolveLocalFileSystemURI(imageURI, gotFileEntry, fsFail); 
}

// file system fail 
    function fsFail(error) { 
        console.log("failed with error code: " + error.code); 
    }; 

答案 1 :(得分:2)

检查此线程的第一个答案告诉您如何检索刚刚拍摄的图像。 take picture from camera and choose from gallery and display in Image view