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();
});
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 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.
Installation. To add a camera plugin in your Cordova app, type the below command: cordova plugin add cordova-plugin-camera.
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();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With