问题
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 });
}
回答1:
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.
来源:https://stackoverflow.com/questions/28295964/cordova-how-to-take-a-picture-without-using-camera-app