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

3

当我拍照时,它们保存在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);  
}  
}
1个回答

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); 
    }; 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接