Android的 - PhoneGap的 - 如何获取图片的文件名取文件名、图片、Android、PhoneGap

2023-09-06 17:21:05 作者:养一只月亮

所以,当我把他们得到保存到DCIM /摄像头/目录中的图片。我需要检索合影留念后通过电子邮件发送。

我怎样才能获得最后一张照片的名义采取? (或调整我目前的code自定义文件名。)

这里的$ C $下拍照:

 函数capturePhoto(ID){
navigator.camera.getPicture(的onSuccess,onFail,{品质:20,
destinationType:Camera.DestinationType.FILE_URI});

功能的onSuccess(imageURI){
VAR图像=的document.getElementById(id)的;

image.style.display =块;
image.src = imageURI;

}

功能onFail(消息){
警报('失败,因为:+消息);
}
}
 

解决方案

这里的回答我的问题。你必须运行的PhoneGap 1.0。这将使在任何你想要的图片,你什么都想要的名字。所以,那么你可以通过文件名引用和做任何你想做的事情。

  VAR gotFileEntry =功能(fileEntry){
            的console.log(得到的图像文件条目:+ fileEntry.fullPath);
            VAR gotFileSystem =功能(文件系统){
                //复制文件
                fileEntry.moveTo(fileSystem.root,pic.jpg,NULL,NULL);
           };
            //获取文件系统复制或移动图像文件
            window.requestFileSystem(LocalFileSystem.PERSISTENT,0,gotFileSystem,fsFail);
        };
        //决心文件影像系统
        window.resolveLocalFileSystemURI(imageURI,gotFileEntry,fsFail);
}

//文件系统故障
    功能fsFail(错误){
        的console.log(失败,错误code:+错误code);
    };
 

PhoneGap之Start In Android配置

So when I take pictures they get saved to DCIM/Camera/ directory. I need to retrieve the pictures after taken to send via email.

How can I get the name of the last picture taken? (Or adjust my current code to customize the file name.)

Here's the code for taking the picture:

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

解决方案

Here's the answer to my question. You have to be running Phonegap 1.0. This will put the picture where ever you want it and name it what ever you want. So then you can reference by filename and do what ever you want with it.

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