【问题标题】:Android - Phonegap - How to get the file name of the picture takenAndroid - Phonegap - 如何获取所拍图片的文件名
【发布时间】:2011-09-05 01:16:25
【问题描述】:

所以当我拍照时,它们会保存到 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);  
}  
}

【问题讨论】:

    标签: android cordova


    【解决方案1】:

    这是我的问题的答案。您必须运行 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); 
        }; 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-19
      • 2011-11-06
      • 2015-11-27
      • 2014-06-30
      • 1970-01-01
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多