1
votes

Phonegap's camera plugin allows to take only single image per invocation.

http://docs.phonegap.com/en/2.2.0/cordova_media_capture_capture.md.html#Capture says in iOS the limit parameter is not supported. One image is taken per invocation.

How to make the following possible.

  1. Invoke camera
  2. Take one picture and save to camera roll in the background. Do not close the camera. Repeat this step.
  3. Need a semi transparent layer with a button 'Show Images' in the bottom part while the camera is active. On clicking this button, close the camera and show the camera roll images.

Is there any code samples available in github?

2
Found an objective code at stackoverflow.com/questions/11806235/…Manu

2 Answers

1
votes

In certain sites it is saying that this limit functionality wont work with ios so any other alternative to implement a camera which dosen't get dismissed untill we press back button such that we can keep clicking photos

0
votes

If you use the capture plugin rather than the camera plugin, you can specify the limit you want to set for the pictures to be taken in one session. See the phonegap 3.0 capture plugin docs for reference. This also works the same in 2.2 I believe.

Here is a some code for how to invoke the capture session.

<script type="text/javascript" charset="utf-8">

// Called when capture operation is finished
//
function captureSuccess(mediaFiles) {
    var i, len;
    for (i = 0, len = mediaFiles.length; i < len; i += 1) {
        uploadFile(mediaFiles[i]);
    }
}

// Called if something bad happens.
//
function captureError(error) {
    var msg = 'An error occurred during capture: ' + error.code;
    navigator.notification.alert(msg, null, 'Uh oh!');
}

// A button will call this function
//
function captureImage() {
    // Launch device camera application,
    // allowing user to capture up to 2 images
    navigator.device.capture.captureImage(captureSuccess, captureError, {limit: 2});
}

// Upload files to server
function uploadFile(mediaFile) {
    var ft = new FileTransfer(),
        path = mediaFile.fullPath,
        name = mediaFile.name;

    ft.upload(path,
        "http://my.domain.com/upload.php",
        function(result) {
            console.log('Upload success: ' + result.responseCode);
            console.log(result.bytesSent + ' bytes sent');
        },
        function(error) {
            console.log('Error uploading file ' + path + ': ' + error.code);
        },
        { fileName: name });
}

</script>

This will get you as far as image filenames and locations for the captured images. I'll try to edit my answer as to then how to get these saved to the camera roll a little later if I figure it out. Note.... this works for video also if you use the captureVideo function. Also included is the uploadFile function of which you could post these images to a server. Inside that function it shows how to reference the full path to the image file and also the image filename. This will be useful in your endeavor to get these to the camera roll. Note the fileTransfer object may require the File plugin, but also definitely requires the FileTransfer plugin.