Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova: how to take a picture without using camera app

I'm working on an Android App with Apache Cordova. I'd like to take a picture without opening camera application. I'd like the camera shoot by clicking a button from my app and save the picture on a specific destination with no interaction with the camera phone application.

Here the simple js I'm using to call getPicture (It produces an asynchronous call to camera application):

function capturePhoto() {
  navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
  destinationType: destinationType.DATA_URL });
}
like image 657
ciz974 Avatar asked Oct 20 '22 18:10

ciz974


1 Answers

Solved using CameraPictureBackground plugin:

function success(imgurl) {
  console.log("Imgurl = " + imgurl);
  //here I added my function to upload the saved pictures
  //on my internet server using file-tranfer plugin
}

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> <br>

You will find your pictures under CameraPictureBackground directory in your device acrhive. I used also file-transfer plugin in order to directly upload the pictures on my server over the internet.

like image 153
ciz974 Avatar answered Oct 22 '22 09:10

ciz974