Cordova take photo in the background

713 Views Asked by At

I am making an application which has to take photo in the background, i.e without interaction. The one am currently using is cordova-plugin-camera but this opens up a interactive option from which the user has to manually click the photo.

navigator.camera.getPicture(successCallback, FailCallback, {
    destinationType: Camera.DestinationType.DATA_URL,
    cameraDirection: 1,
    quality: 25,
    targetWidth: 300,
    targetHeight: 300
});
1

There are 1 best solutions below

3
On

use CameraPictureBackground plugin:

Example code:

function success(imgurl) {
  console.log("Imgurl = " + imgurl);
}

function onFail(message) {
    alert('Failed because: ' + message);
}

function CaptureBCK() {
    var options = {
      name: "Image", //image suffix
      dirName: "CameraPictureBackground", //foldername
      orientation: "portrait", //or landscape
      type: "back" //or front
    };

    window.plugins.CameraPictureBackground.takePicture(success, onFail, options);
}

<button onclick="CaptureBCK();">Capture Photo</button>

You will find your pictures under CameraPictureBackground directory in your device acrhive.