Gurpreets11
Gurpreets11

Reputation: 2351

PhoneGap - Android - how to save the capture image from camera in the sd card

I'm new in PhoneGap Android developer. I'm making an application in android using the phonegap. I want to take picture from the device camera and then i want to display it on the screen after taking the image from device and as well as store that captured image in the SD Card. Can you please tell me how i can do this.

Gurpreet singh

Upvotes: 2

Views: 13692

Answers (2)

jiten
jiten

Reputation: 5264

For saving in the SD card......

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) {
        fileEntry.createWriter(gotFileWriter, fail);
    }

    function gotFileWriter(writer) {

        var photo = document.getElementById("image");
        writer.write(photo.value);

    }

    function fail(error) {
        console.log(error.code);
    }

Upvotes: 4

dhaval
dhaval

Reputation: 7659

Refer the following gist which does capture the image from camera in both data and file mode.

Camera Capture Sample Gist

Reference from

Capture camera image - Phonegap Doc

Upvotes: 4

Related Questions