Android 使用phonegap将图像保存到库中

Android 使用phonegap将图像保存到库中,android,cordova,Android,Cordova,如何使用android phonegap将图像保存到手机库 我尝试了以下代码: function save(){ document.addEventListener("deviceready", onDeviceReady, false); } // PhoneGap is ready // function onDeviceReady() { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fai

如何使用android phonegap将图像保存到手机库

我尝试了以下代码:

   function save(){
document.addEventListener("deviceready", onDeviceReady, false);
}



// PhoneGap is ready
//
function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
    fileSystem.root.getFile("pic.jpg", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
console.log(fileEntry.fullPath);
    fileEntry.createWriter(gotFileWriter, fail);
}

function gotFileWriter(writer) {
    var photo = document.getElementById("dwnldImg");
    writer.write(photo.value);
}
但它将图像保存到我的项目目录中,即
file:///data/data/pack.name/pic.jpg
。 如何使其显示在移动多媒体资料中

请尝试使用以下方法:

function capturePhoto() {
    // Take picture using device camera and retrieve image as base64-encoded string

    navigator.camera.getPicture(onPhotoDataSuccess, onFail,{
        quality : 25, 
        destinationType : Camera.DestinationType.FILE_URI, 
        sourceType : Camera.PictureSourceType.CAMERA, 
        allowEdit : true,
        encodingType: Camera.EncodingType.JPEG,
        popoverOptions: CameraPopoverOptions,
        saveToPhotoAlbum: true });         
}