Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take Multiple photo using Cordova Camera Plugin

I have been testing on Android and my goal is to take multiple photos, using either Cordova Camera or Media Capture, and save them to a gallery that will automatically correct/fix orientation. The back button in conjunction with the Media Capture, cancels the photo taking session, but seems to save the photos without corrected orientation. If I take photos using Camera plugin I get exactly what I need but I can only take one photo at a time. Is there a way to wrap navigator.camera.getPicture into a loop that will take a photo until the cancel/back button is applied. It seems that the function is asynchronous and I haven't been able to get it to work no matter the approach.

What's strange is if I use the File manager to manually copy the files saved by media capture plugin into the gallery or the same folder the orientation is corrected.

UPDATE: I solved it by calling a function to take a picture again in the success event.

function takePicture(){

navigator.camera.getPicture( cameraSuccess, cameraError, {
        quality: 50,
        destinationType: Camera.DestinationType.FILE_URI,
        correctOrientation: true,
        saveToPhotoAlbum: true
    }); 

}

function cameraSuccess(uri){   
    //alert(uri);
    takePicture();    
}

function cameraError(message){
    alert("Canceled!"); 
}

$('#ThumbnailTest_buttonTakePhotosNow').click(function(){
    takePicture();
});
like image 291
navarro_miguel Avatar asked May 07 '15 01:05

navarro_miguel


People also ask

What is Cordova camera?

This plugin defines a global navigator. camera object, which provides an API for taking pictures and for choosing images from the system's image library. Although the object is attached to the global scoped navigator , it is not available until after the deviceready event.

What are Cordova plugins?

What is a Cordova plugin? A plugin is a bit of add-on code that provides JavaScript interface to native components. They allow your app to use native device capabilities beyond what is available to pure web apps.

Which command is used to install camera plugin?

Installation. To add a camera plugin in your Cordova app, type the below command: cordova plugin add cordova-plugin-camera.


1 Answers

OP Mentioned solution in Question so I think better to add as Answer:

You can do this by calling a function to take a picture again in the success event.

function takePicture(){

navigator.camera.getPicture( cameraSuccess, cameraError, {
        quality: 50,
        destinationType: Camera.DestinationType.FILE_URI,
        correctOrientation: true,
        saveToPhotoAlbum: true
    }); 

}

function cameraSuccess(uri){   
    //alert(uri);
    takePicture();    
}

function cameraError(message){
    alert("Canceled!"); 
}

$('#ThumbnailTest_buttonTakePhotosNow').click(function(){
    takePicture();
});
like image 128
NullPointer Avatar answered Oct 11 '22 16:10

NullPointer