gendy
gendy

Reputation: 11

saving image into gallery with phonegap

How can I save an image to gallery of the mobile with android phonegap?

I tried this code:

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

But it saves the image into my project directory which is file:///data/data/pack.name/pic.jpg. how can i make it appear in the mobile gallery

Upvotes: 0

Views: 1450

Answers (1)

tionne jones
tionne jones

Reputation: 133

try using this:

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

Upvotes: 1

Related Questions