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

13,671

Solution 1

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

Solution 2

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

Share:
13,671
Preet_Android
Author by

Preet_Android

I'm an Android application developer. My working area is Java, Android and phone gap. I have developed more than 30 Android Application in which more than 20 is live on Google Play store. My Phonegap application are also live on Google play store as well as on iTunes(apple store). My technical skill are Java, Android, Phone gap, Oracle DB, MySQL, SQLite, HTML5, XML, javascript, jQuery and JSON. Thanks Happy Coding!!!

Updated on June 05, 2022

Comments

  • Preet_Android
    Preet_Android almost 2 years

    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

  • ninjasense
    ninjasense about 12 years
    The example from the Phonegap documentation did not work for me, however the top one did. Thanks!